Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching a log for a specific pattern & exporting it-can it be done? 2

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
(Elementary user)

I have a very large log file that contains thousand of lines and I would like to search for a specific pattern in this log and output this to another file.

I would like to search for this pattern: */@*

A line entry in the log would look like this:

May 4 11:10:46.17 recv [19380] 4BB4CBA84 < 6>: 'A04BB4CBA84' message From:'<user@somedomain.com>' To:'<jon.doe/@anotherdomain.com>' Size: 14072

Is there a way of:
1) searching the log file,
2) looking for matches
3) putting those lines containing my match in another file

Best regards
 
Yes, you can use a pattern matching language called regular expressions. As far as matching the patterns and exporting them to a file, the tool SED will do just this.

I apologize for the terseness of the reply. I don't have much time at the moment otherwise I would try to give you some examples. Looking for the above two items should get you started in the right direction, though.
 
Hi

Sounds like [tt]grep[/tt] would be enough. And [tt]grep[/tt] ( especially the GNU implementation ) is usually much faster than [tt]sed[/tt] or other complex tools.
Code:
grep '/@' log.file > match.file
And given that actually you are looking for a fixed string anywhere in the line, you can speed it up by turning off regular expression matching :
Code:
grep -F '/@' log.file > match.file


Feherke.
 
Thank you so much, this worked beautifully and was very fast!

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top