LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2014, 02:56 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Rep: Reputation: 5
Problem finding variable data


varld=abc
sed -n -e '/$varld/! w dummy4.txt' -e '/$varld/{:a;n;w dummy5.txt' -e 'ba}' dummy3.txt

The instruction above cannot fine the 'abc' in varld. If I hard code the 'abc' into the instruction, as below, it works.

sed -n -e '/abc/! w dummy4.txt' -e '/abc/{:a;n;w dummy5.txt' -e 'ba}' dummy3.txt

Can someone tell me how to get the sed to find and use the data in $varld?

Thanks.
 
Old 10-10-2014, 07:01 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,252

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
Quote:
Originally Posted by battles View Post
varld=abc
sed -n -e '/$varld/! w dummy4.txt' -e '/$varld/{:a;n;w dummy5.txt' -e 'ba}' dummy3.txt

The instruction above cannot fine the 'abc' in varld. If I hard code the 'abc' into the instruction, as below, it works.

sed -n -e '/abc/! w dummy4.txt' -e '/abc/{:a;n;w dummy5.txt' -e 'ba}' dummy3.txt

Can someone tell me how to get the sed to find and use the data in $varld?

Thanks.
the single quotes used in the sed's should be double quotes otherwise $varld is taken literally instead of being replaced by the contents of the variable
 
Old 10-10-2014, 07:07 PM   #3
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Original Poster
Rep: Reputation: 5
Thanks. I'll have to change all single quotes in my sed examples to double.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
finding and filtering data between two files atjurhs Linux - Newbie 6 09-23-2012 04:59 AM
Finding data in large no. of files cooker97 Linux - Newbie 7 07-10-2012 04:48 AM
problem while comparing awk field variable with input variable entered using keyboard vinay007 Programming 12 08-23-2011 01:44 AM
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 03:29 PM
Finding the signedness of a variable. jopu Linux - General 1 11-04-2009 04:48 AM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration