LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 01:56 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
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, 06:01 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
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, 06:07 PM   #3
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

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


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 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 03:59 AM
Finding data in large no. of files cooker97 Linux - Newbie 7 07-10-2012 03:48 AM
problem while comparing awk field variable with input variable entered using keyboard vinay007 Programming 12 08-23-2011 12:44 AM
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
Finding the signedness of a variable. jopu Linux - General 1 11-04-2009 03:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:33 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