LinuxQuestions.org
Help answer threads with 0 replies.
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 07-01-2009, 08:35 AM   #1
rany
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Thumbs up 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.
 
Old 07-01-2009, 08:43 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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).
 
Old 07-02-2009, 02:13 AM   #3
rany
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks you very much !!!

It works
 
  


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
[SOLVED] sed help - replace line feed with different character bradvan Programming 7 04-23-2012 12:31 AM
sed - How do you replace end of line with a space pppaaarrrkkk Programming 7 02-07-2011 12:27 PM
replace a pattern with a line using sed/awk lokeshn05 Linux - Newbie 3 05-06-2009 04:01 PM
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 08:01 PM
sed: replace one line with >one line bbeers Programming 3 11-19-2002 06:27 PM


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