LinuxQuestions.org
Review your favorite Linux distribution.
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 11-01-2011, 07:07 PM   #1
newbieLnx
LQ Newbie
 
Registered: Aug 2011
Posts: 9

Rep: Reputation: Disabled
Sed dynamic replace


I am trying to use sed to replace an occurrence of a word with a word from a previous location in the file. Is this possible?

For example, in the file below, I would like to replace the value for DECLARE2 with the value dynamically found in DECLARE1

DECLARE1('ABCDEF')
Something else
DECLARE2('12345')

Thanks
 
Old 11-02-2011, 01:26 PM   #2
Stephen Morgan
Member
 
Registered: Feb 2011
Location: England
Distribution: Slackware
Posts: 163

Rep: Reputation: 17
I don't think sed can do that, no. You could use awk to do that, or a combination of utilities like grep and cut with sed. grep to find the line with DECLARE1, cut to remove the extraneous characters, sed to replace.

But sed doesn't really do variables, no. awk does, and as it works line by line it might be better for what you're after.
 
  


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
Help with sed doing find and replace lostNspace Programming 2 08-25-2011 07:23 PM
find or replace through sed adarshmca Linux - Newbie 3 12-27-2010 11:35 PM
sed search replace tomerbd1 Linux - General 9 04-10-2008 04:31 AM
How do I replace ' with sed.... @ngelot Linux - Newbie 2 11-02-2007 07:04 PM
Replace substring with SED marri Programming 2 07-09-2005 05:18 PM

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

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