LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SED - replace line after substing (https://www.linuxquestions.org/questions/linux-newbie-8/sed-replace-line-after-substing-736934/)

rany 07-01-2009 07:35 AM

SED - replace line after substing
 
Hi,

How do I replace the line content after a particular string ?

For example:
If I have the below lines;
ABCD
1234\00
EFGH
5678\00

How do I replace the line after "ABCD" string to be 1111.
ABCD
1111\00
EFGH
5678\00

Please note that I don't know the line content after the string.

colucix 07-01-2009 07:43 AM

Use the n command of sed to go to the next line, then apply the substitution:
Code:

sed '/ABCD/{n; s/.*\(\\00\)/1111\1/} file
This changes every string from the beginning of the line after ABCD to "\00" (which is preserved).

rany 07-02-2009 01:13 AM

Thanks you very much !!!
 
It works


All times are GMT -5. The time now is 03:44 AM.