Awk Script for generating a report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk Script for generating a report
# 1  
Old 10-31-2008
Awk Script for generating a report

Hi all,

I have a log file of the below format.

[asdfg@st9872] 20081016:000042 asdflasjdf asljfljs asdflasjf safjl
[kronos@jd0121] 20081016:000229 /lask/ajlsdf/askdfjsa
[cak416@po0121] 20081016:000229 /lashflas /askdfaslj hsfhsahf
[close@as0121] 20081016:000304 lasflasj ashfashd
[cak416@sadfjk0121] 20081016:000304 lajfasdf ashfashdfhs

I need to generate a report based on the log file based on the timestamp. I need to search for particular errror messages that were encountered on an hourly basis from the log file. The second field here is the timestamp which is of the form yyyymmdd:hhmmss eg:20081016:000042. I need to create hour by hour statistics from this log file.

like errors encountered between 20081016:000042 and 20081016:230000

I tried using awk inside a shell script, but it was crude way doing things and it depended on the user input for the time, but what I need the script to do is to capture the information automatically from the log file based an hour by our basis.

below is the script that I tried. I am new to awk and I am clueless of doing this.

the variables nmbr1 and nmbr2 are being asked from the user through a shell script.

filename="/opt/tmp/ca/fds/logs/proof.out_20"
filename2="${filename}${dt}"
awk -v nmbr1=${nmbr1} -v nmbr2="$nmbr2" -v outfile="$outfile" '
{
FS=":";
if ((($2-$6) > nmbr1) && (($2-$6) < nmbr2)){
print $2,$3 >>outfile;
}
}
END {}' $filename2

#/home/i4zuss/proof.out_20081016
result=`grep "returned 7" $outfile | wc -l`
echo "Failure Return code 7 =" $result >>/tmp/results.out;
result=`grep "returned 5" $outfile | wc -l`
echo "Failure Return code 5 =" $result >>/tmp/results.out;
result=`grep "Max=30" $outfile | grep "acm" | wc -l`

Let me know if you guys have any idea abt how to solve this.
# 2  
Old 10-31-2008
Quote:
Originally Posted by manoj.naidu
...
The second field here is the timestamp which is of the form yyyymmdd:hhmmss eg:20081016:000042. I need to create hour by hour statistics from this log file.

like errors encountered between 20081016:000042 and 20081016:230000
...
If you grep from 00 to 23 this is a daily log filter:
Code:
awk '$2 ~ /^20081016/'  log > 20081016.log

# 3  
Old 10-31-2008
thanks. Actually I want to search for a string and count the instances of that string in the log entries every hour.. like between 00:00:00 hrs and 00:01:00 hrs and so on. Let me know how this can be done.

Thanks for your prompt reply.
# 4  
Old 11-01-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Generating all possible combinations of values in field 1 (awk)

Input: A|1 B|2 C|3 D|4 Output: A+B|3 A+C|4 A+D|5 B+C|5 B+D|6 C+D|7 A+B+C|6 A+B+D|7 A+C+D|8 B+C+D|9 A+B+C+D|10 I only managed to get the output for pairs of $1 values (i.e. combination of length 2): (4 Replies)
Discussion started by: beca123456
4 Replies

2. Shell Programming and Scripting

Generating summary data (use awk?)

I have a data file similar to this (but many millions of lines long). You can assume that it is totally unsorted but has no duplicate rows. Date ,Tool_Type ,Tool_ID ,Time_Used 3/13/2014,Screwdriver,Screwdriver02, 6 3/13/2014,Screwdriver,Screwdriver02,20... (2 Replies)
Discussion started by: Michael Stora
2 Replies

3. Shell Programming and Scripting

Comparing two files and generating the report

Hi All, What am trying to do is generate the report by compating two files. File A ----------- 111 22222 3333 222 55555 7777 File B ----------- 11A 22222 3333 333 55555 7778 Now the report should be as follows Added: 333 55555 7778 Removed: (6 Replies)
Discussion started by: Prashantckc
6 Replies

4. Shell Programming and Scripting

Novice in shell scripting - generating report

Hi I recently joined a project where I have been asked to generate a report using shell script accessing UNIX box. I have no idea on how to do it as I am a beginner and learning shell scripts. Suppose I have a XML: <XYZRequest> <effectiveDate>someDate</effectiveDate>... (2 Replies)
Discussion started by: vat1kor
2 Replies

5. Shell Programming and Scripting

Generating multiple new columns with awk

Hi, I'm trying to reformat a file to create a new columns reflecting the previous 2 over and over. By that I mean currently each observation has two columns and I want to create a third which has a value equal to 1 minus the sum of the previous two. This is slightly complicated as 1) I... (6 Replies)
Discussion started by: reformatplink
6 Replies

6. Shell Programming and Scripting

generating report in Excel(Open office) using shell scripting

Hello All, I need to execute around 15 queries after which all data should come in Excel format. Executing 15 queries is not a problem. Problem is how to present/put data in excel. kindly suggest me how to start, what to study or what should i do. thanks, (1 Reply)
Discussion started by: shubham8787
1 Replies

7. Shell Programming and Scripting

awk not generating the expected output

Hi, I am presently stuck in a csv file. INPUT CSV baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played EXPECTED OUTPUT CSV ... (7 Replies)
Discussion started by: scripter12
7 Replies

8. Shell Programming and Scripting

Generating a count report

Hi, I want to generate a report for count mismatching. Steps followed for creating a script for file in 1). I have to fetch the file name from the checksum.out #customer_information_ 2). Added Detail #customer_information_Detail 3). Check the file exist or not. 3.1.1)if the the file... (1 Reply)
Discussion started by: number10
1 Replies

9. Shell Programming and Scripting

Parsing out the logs and generating report

My file will contain following(log.txt): start testcase: config loading ...... error XXXX ..... end testcase: config loading, result failed start testcase: ping check ..... error ZZZZZ ..... error AAAAA end testcase: Ping check, result failed I am expecting below output. ... (4 Replies)
Discussion started by: shellscripter
4 Replies

10. Shell Programming and Scripting

Generating a report -Formatted printing -Urgent

Hi, My aim is to generate a report using shell script. There are various formats fields coloumns etc. I want to print in a single line (row) but in different coloumn as given below: field1 field2 field3 field4 ....... ....... ...... ....... The spacing... (1 Reply)
Discussion started by: jisha
1 Replies
Login or Register to Ask a Question