Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

SED to remove a line above and lines below.

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-08-2010
chiewming chiewming is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 18 November 2010, 1:49 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
SED to remove a line above and lines below.

LinuxHi All,

I need help on removing lines in a text file.

Sample file :
Quote:

Client=0x 0
IPAddress=113.211.45.33
Client=0
ClientV=0
........
Uncomp=0
Comp=0
When there is a match ip for IPAddress in my `cat ip.out`, proceed delete line above until string "Comp" is found.

Thank you very much.

---------- Post updated at 12:56 AM ---------- Previous update was at 12:53 AM ----------

I found very useful SED in this forum but i got no idea how to manipulate it.


Code:
sed -rn '/(0\.0000 *){6}/{n;n;x;d};x;1d;p;${x;p}'

Linux

Last edited by Scott; 11-08-2010 at 03:23 AM.. Reason: Code tags
Sponsored Links
    #2  
Old Unix and Linux 11-08-2010
michaelrozar17's Unix or Linux Image
michaelrozar17 michaelrozar17 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 22 September 2016, 3:57 AM EDT
Location: IN
Posts: 894
Thanks: 15
Thanked 183 Times in 174 Posts
To be precise could you pls post the desired output from the above sample file..
Sponsored Links
    #3  
Old Unix and Linux 11-08-2010
birei birei is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 9 January 2016, 5:40 AM EST
Location: Madrid, Spain
Posts: 628
Thanks: 8
Thanked 174 Times in 171 Posts
Hi,

According to michaelrozar17, I find the post not clear enought. Even so I will make a try:

Code:
$ cat infile
Client=0x 0
IPAddress=113.211.45.33
Client=0
ClientV=0
........
Uncomp=0
Comp=0

$ sed '/^IPAddress=113\.211\.45\.33/I , /^Comp=/I { /^IPAddress=/I! d }' infile
Client=0x 0
IPAddress=113.211.45.33

Regards,
Birei
    #4  
Old Unix and Linux 11-11-2010
chiewming chiewming is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 18 November 2010, 1:49 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Guy,

Below is the sample output file

Quote:
Client=0x 0
IPAddress=200.200.200.200
Client=0
ClientV=0
........
Uncomp=0
Comp=0

Client=0x 0
IPAddress=113.211.45.33
Client=0
ClientV=0
........
Uncomp=0
Comp=0

Client=0x 0
IPAddress=10.10.10.10
Client=0
ClientV=0
........
Uncomp=0
Comp=0
TO

Quote:
Client=0x 0
IPAddress=200.200.200.200
Client=0
ClientV=0
........
Uncomp=0
Comp=0

Client=0x 0
IPAddress=10.10.10.10
Client=0
ClientV=0
........
Uncomp=0
Comp=0
I get it resolved by combining all rows and add a newline whenever there is Client string and finally grep -v.

But I still keen to know how to doit.

Thank you in advance.
Sponsored Links
    #5  
Old Unix and Linux 11-11-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 December 2016, 6:40 AM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
Try this:

Code:
awk '!/113.211.45.33/' RS= ORS="\n\n" file

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove duplicate lines (the first matching line by field criteria) joggdial3000 Shell Programming and Scripting 6 05-03-2010 12:18 PM
Remove All Lines Between Two Unique Lines Grizzly Shell Programming and Scripting 2 02-26-2010 06:08 AM
Break lines up into single lines after each space in every line lewk Shell Programming and Scripting 7 10-14-2009 10:33 AM
shell script to remove all lines from a file before a line starting with pattern raksha.s Shell Programming and Scripting 2 03-29-2009 08:13 AM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 03:36 PM



All times are GMT -4. The time now is 04:34 AM.