LinuxQuestions.org
Visit Jeremy's Blog.
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 04-18-2009, 05:51 PM   #1
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Rep: Reputation: 15
using grep -v / Grep exclusions


Hello,

I have a large text file and want to be able to extract certain stuff out. For instance i do not want to see any instances of:


[**] [1:410:5] ICMP Fragment Reassembly Time Exceeded [**]
[Classification: Misc activity] [Priority: 3]
ICMP TTL:110 TOS:0x20 ID:28112 IpLen:20 DgmLen:576
Type:11 Code:1 TTL EXCEEDED TIME EXCEEDED IN FRAG REASSEMBLY
** ORIGINAL DATAGRAM DUMP:
UDP TTL:111 TOS:0x0 ID:39543 IpLen:20 DgmLen:1388 MF
Len: 1500 Csum: 33099
(520 more bytes of original packet)
** END OF DUMP

i was doing grep -v "ICMP Fragment Reassembly Time Exceeded" [filename]

this just excluded that one line, but i want to be able to exclude 8-9 lines after that. Can anyone help me exclude multiple lines after a pattern is matched?

Thank you
 
Old 04-18-2009, 05:55 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,823

Rep: Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611
Code:
man grep
Quote:
Context Line Control
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing
a group separator (--) between contiguous groups of matches. With the -o or
--only-matching option, this has no effect and a warning is given.
 
Old 04-18-2009, 05:57 PM   #3
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
i already did a man on grep, that is why im asking this question.
 
Old 04-18-2009, 07:22 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk '/ICMP Fragment Reassembly Time Exceeded/{f=1}/END OF DUMP/{f=0;next}!f' file
 
Old 04-18-2009, 08:14 PM   #5
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
thank you very much!!!
 
Old 04-18-2009, 08:17 PM   #6
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
can you specify the number of files to eliminate instead of specifying end of dump?
 
Old 04-18-2009, 08:49 PM   #7
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,823

Rep: Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611
What, so grep -vA9 doesn't work? I'll admit I didn't try it, but it sounded good..
 
Old 04-18-2009, 09:24 PM   #8
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
AlucardZero, i think you need to read the man page
 
Old 04-18-2009, 09:51 PM   #9
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,823

Rep: Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611Reputation: 611
I thought the -v might apply after the -A8, obviously I was wrong. So with -v, -A changes to "Print NUM lines of trailing context after nonmatching lines"; awk is the best way to do this is previously stated.
 
Old 04-18-2009, 11:53 PM   #10
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 333

Rep: Reputation: 141Reputation: 141
This uses GNU sed to delete the matched line and the 8 lines after it.
Code:
sed '/ICMP Fragment Reassembly Time Exceeded/,+8 d' infile > outfile
 
  


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
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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