LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-22-2008, 01:18 AM   #1
karthikn7974
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Rep: Reputation: 0
Question Text Parser


I am having a text file as follows

say server.txt

Code:
Date        Time          server      ip                error code
--------------------------------------------------------------------------
02/21/2008   18:10:14   server1  xxx.xxx.xxx.xxx    6
02/21/2008   08:10:14   server2  xxx.xxx.xxx.xxx    196
03/21/2008   21:10:14   server8  xxx.xxx.xxx.xxx    96
03/21/2008   12:10:14   server9  xxx.xxx.xxx.xxx    132
04/21/2008   06:10:14   server4  xxx.xxx.xxx.xxx    254
04/21/2008   18:10:14   server6  xxx.xxx.xxx.xxx    6
I need a script to write lines to new file which satisfy the below condition

if Date=02/21/2008 and server=server1 and error code=6 and ip=xxx.xxx.xxx.xxx then that line should be written to output.txt

Please let me know any script can satisfy all 4 condition strings in a line...

Thanks in advance
 
Old 04-22-2008, 01:31 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
How big is the file?

Not efficient or neat, but

cat server.txt | grep 02/21/2008 | grep server1 | grep "xxx.xxx.xxx.xxx 6" > outfile.txt

Edit - losing whitespaces - you would need the correct number of spaces between x and 6

Edit 2 or you could

cat server.txt | grep 02/21/2008 | grep "server1 xxx.xxx.xxx.xxx 6" > outfile.txt

Last edited by billymayday; 04-22-2008 at 01:33 AM.
 
Old 04-22-2008, 02:30 AM   #3
karthikn7974
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Lightbulb

Hi Bill,

Thanks for your info,

But my friend sent another script using awk which is working fine too, just to share with this LQ

Code:
awk '{
if($1=="02/21/2008" && $3=="server1" && $4=="xxx.xxx.xxx.xxx " && $5==6)
print
}' filename
Thanks
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
INI Parser Natasl Programming 6 08-26-2007 02:59 PM
String Parser pawan_songara Programming 1 08-27-2006 09:58 AM
Text Parser (TPM) Croaker Linux - Newbie 3 10-05-2005 12:18 AM
URI parser nodger Programming 1 05-03-2004 10:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:13 AM.

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
Open Source Consulting | Domain Registration