LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 10: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, 11:33 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 12:24 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 12:25 AM.
 
  


Reply



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 10:01 AM
[SOLVED] trouble expanding 4+TB GPT partition after expanding hardware RAID-5 volume muad'dib Linux - Enterprise 6 09-26-2009 05:01 PM
Sed and variables oden Programming 9 07-29-2007 04:36 PM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 05:17 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:46 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration