LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Having trouble expanding variables with sed (https://www.linuxquestions.org/questions/linux-general-1/having-trouble-expanding-variables-with-sed-4175465571/)

jdog-ky 06-11-2013 10:51 AM

Having trouble expanding variables with sed
 
I'm trying to use sed in a script to filter records in a log file by providing 2 variables (flight & Date)to the script. Each record is seperated by a blank line in the log.
My filter works (to look for flt 377 on 2013-05-09) as:
sed -e '/./{H;$!d;}' -e 'x;/scheduledFlightNumber>377/!d;/scheduledDepartureTimestamp>2013-05-09/!d' Logfile
but I want to be able to provide a flt# and date as arguments.
I've tried:
sed -e '/./{H;$!d;}' -e 'x;/scheduledFlightNumber>${flt}/!d;/scheduledDepartureTimestamp>${Date}/!d' Logfile
but it doesn't expand the ${flt} and ${Date}. I've also tried using "eval" in front of the sed command, but no joy.
This is my first post, but I've found many solutions previously (Thanks).
TIA for any future help.

linosaurusroot 06-11-2013 11:33 AM

Variables are not expanded inside single quotes '$here' but they are inside double quotes "$here".

That's a shell feature nothing to do with sed.

chrism01 06-12-2013 12:24 AM

It'd be nice to see a few relevant lines of the input file.
Do you just want the lines that match both of the strings, or just specific fields within those lines.


All times are GMT -5. The time now is 03:48 PM.