LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-11-2013, 11:51 AM   #1
jdog-ky
LQ Newbie
 
Registered: Jun 2013
Posts: 1

Rep: Reputation: Disabled
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.
 
Old 06-11-2013, 12:33 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 845
Blog Entries: 2

Rep: Reputation: 212Reputation: 212Reputation: 212
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.
 
Old 06-12-2013, 01:24 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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.

Last edited by chrism01; 06-12-2013 at 01:25 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SED with variables RocketJumper Programming 15 02-06-2011 11:01 AM
[SOLVED] trouble expanding 4+TB GPT partition after expanding hardware RAID-5 volume muad'dib Linux - Enterprise 6 09-26-2009 06:01 PM
Sed and variables oden Programming 9 07-29-2007 05:36 PM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 06:17 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


All times are GMT -5. The time now is 11:46 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration