Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-01-2011, 08:07 PM   #1
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

Something else

Old 11-02-2011, 02:26 PM   #2
Stephen Morgan
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.


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

All times are GMT -5. The time now is 04:50 AM.

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