LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sed dynamic replace (https://www.linuxquestions.org/questions/linux-newbie-8/sed-dynamic-replace-911362/)

newbieLnx 11-01-2011 07:07 PM

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

Stephen Morgan 11-02-2011 01:26 PM

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.


All times are GMT -5. The time now is 01:55 PM.