Gawk filter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk filter
# 1  
Old 06-07-2010
Gawk filter

People,

Ive been trying to make a script but i just cant figure it out.

Problem/ Case:

I have a logfile.txt that contains data. The only two things i need to filter on = $1 (date), $6 (errorcode).

In the script i am trying to make, u need to fill in a date. So he searches on that date on a specific errorcode and counts the total or give the lines.

Making it in Win XP (Gawk), and on the end it must be a .bat file.


So far i got this:

To get the input date from the user:
Code:
gawk.exe "BEGIN {getline; print \"Date = \"$0;}"

The filter:
Code:
gawk.exe "$6 == "1111" && $1 ~ /9-1-2009/ {n++}; END{print n}" c:\log.txt

ps. (1111 is a errorcode dont mind)


How can i combine those so i can use the getline date var in the filter. And it has to work in a .bat file.

Thank u for your help and time Smilie

Last edited by Franklin52; 06-09-2010 at 07:41 AM.. Reason: Please use code tags!
# 2  
Old 06-08-2010
Hi,

Not sure about the Windows version of gawk and Windows scripting but have a look at the -v switch in the man pages. You only need to capture the user input in your script and inject it in the awk snippet.

Code:
awk -v dte_filter="$1" '<awk bloc>' file

# 3  
Old 06-09-2010
Thank u for the tip.

I'm working it out, but i can't get further then this.

Code:
gawk.exe -v dte_filter="$1"; "$6 == "1111" && $1 ~ $dte_filter {n++}; END{print n}" c:\log.txt

If i remove the c:\log.txt it asks me for input. But if i put in the c:\log.txt, it runs the script without i can give my input.

How do i get this script working, so it asks me for a date and runs in though the gawk filter??

Last edited by Franklin52; 06-09-2010 at 07:42 AM.. Reason: Please use code tags!
# 4  
Old 06-10-2010
Is there someone that can help me with it?

I just need to save the userinput and run it though the AWK filter.

The AWK filter
Code:
 "$6 == "1111" && $1 ~ $date {n++}; END{print n}" c:\log.txt

The USER date input
Code:
 gawk.exe -v date="$1"

How do i combine those?

Many thanks for the one that can help me Smilie
# 5  
Old 06-10-2010
Try escaping '-' in date. Or better, post a few lines from your input file.
# 6  
Old 06-10-2010
Code:
 
4-3-2009	10:51:33	MSFTPSVC	Warning	None	100	N/A	MSDNAA	The server was unable to logon the Windows NT account 'test' due to the following error: Logon failure: unknown user name or bad password.  The data is the error code.
4-3-2009	10:51:32	MSFTPSVC	Warning	None	100	N/A	MSDNAA	The server was unable to logon the Windows NT account 'test' due to the following error: Logon failure: unknown user name or bad password.  The data is the error code.
4-3-2009	10:51:31	MSFTPSVC	Warning	None	100	N/A	MSDNAA	The server was unable to logon the Windows NT account 'test' due to the following error: Logon failure: unknown user name or bad password.  The data is the error code.

The user needs to give a date. Where the awk filter sorts on the date and the error code (example 100).
# 7  
Old 06-10-2010
Try,

Code:
gawk -v date="5-3-2009" '$1 ~ date && $6 == 1111' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk and regexp

Hello, This is a problem I've worked on a while and can't figure out. There is a file.txt ..some stuff.. ] ] ..some stuff.. The Awk program is trying to extract the year portion of the birth and death ("98: and "2nd C.") using the below technique #!/bin/awk @include... (5 Replies)
Discussion started by: Mid Ocean
5 Replies

2. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

3. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

4. Shell Programming and Scripting

Increment Gawk

Hi, I have a small query with gawk which i'm unsure how to solve. My csv input data is as follows: 1 58352.9 34549 -469.323 LINE_149 2 58352.9 34499 -469.323 LINE_149 3 58352.9 34549 -469.323 LINE_151 4 58352.9 34503.4 -489.841 LINE_151 5 58352.9 34549 -469.323 LINE_152 6 58352.9... (1 Reply)
Discussion started by: theflamingmoe
1 Replies

5. Shell Programming and Scripting

Doubt with gawk

Hi All, I have a doubt with gawk. I have a shell script "cleanup" which calls a gawk script "cleanawk" in it. we have two unix servers epsun532 and wpsun712. So i tested the script in both the environments. In epsun532 while calling the gawk script i just mentioned something like this ... (1 Reply)
Discussion started by: Diddy
1 Replies

6. Shell Programming and Scripting

Help with gawk command

Hi, I have a situation. in a particular file , from the 9th column i have to match a particular pattern . i want a second file which is made by excluding them. I wrote a code like this. gawk '$9~/^(SPI|OTC|SAX)$/' /home/ceh1/ceh_prod/plx_"$mydate"_old.tsv >>... (1 Reply)
Discussion started by: pranabrana
1 Replies

7. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

8. Shell Programming and Scripting

gawk and bash

Hi. I'm having trouble using gawk within a bash script and I can't figure out why. I have a command that takes in a data file with two columns, the first one numbers and the second words. My code takes each line, and prints the word its corresponding number of times. The code works from the... (2 Replies)
Discussion started by: cdislater
2 Replies

9. Shell Programming and Scripting

gawk will work or not ?

Hai I am using bash-2.03$ bash --version GNU bash, version 2.03.0(1)-release (sparc-sun-solaris) I am not able to use gawk command its showing command not found , why ? Eg: awk 'NR==1' fix.txt | gawk 'BEGIN { FIELDWIDTHS = "3 2" } { printf($1"|"$2); }'... (3 Replies)
Discussion started by: tkbharani
3 Replies

10. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question