The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl XML:Parser help vincaStar Shell Programming and Scripting 0 03-31-2008 01:01 AM
xml parser in perl zedex Shell Programming and Scripting 1 03-29-2008 11:37 AM
string parser flextronics Shell Programming and Scripting 8 08-28-2006 04:39 AM
command line parser mile1982 High Level Programming 0 09-05-2004 10:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 04-22-2008
karthikn7974's Avatar
karthikn7974 karthikn7974 is offline VIP Member  
Supporter
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 58
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
  #2 (permalink)  
Old 04-22-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,097

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

  #3 (permalink)  
Old 04-22-2008
karthikn7974's Avatar
karthikn7974 karthikn7974 is offline VIP Member  
Supporter
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 58
Question

There is no error in using your awk, but no result. i see only a blank file. can u give more details.
  #4 (permalink)  
Old 04-22-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Remove the extra space after the IP address ($4=="xxx.xxx.xxx.xxx " ) in the awk command.

It works perfectly fine.
  #5 (permalink)  
Old 04-22-2008
karthikn7974's Avatar
karthikn7974 karthikn7974 is offline VIP Member  
Supporter
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 58
Question

This is wat i tried

  #6 (permalink)  
Old 04-22-2008
karthikn7974's Avatar
karthikn7974 karthikn7974 is offline VIP Member  
Supporter
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 58
this is the command i used
$ sh aaa.sh 02/21/2008 server1 xxx.xxx.xxx.xxx 6 input.txt
  #7 (permalink)  
Old 04-22-2008
karthikn7974's Avatar
karthikn7974 karthikn7974 is offline VIP Member  
Supporter
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 58
Lightbulb

Hi ALL,

It Works fine .

thanks to all.

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0