Need expertise on awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need expertise on awk
# 1  
Old 09-13-2011
Need expertise on awk

Hi everyone. I need some help on how to fix this.

I am getting positive result using the log file below and this command
Code:
awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$2 ~ t && $7 ~ main { first = $0; getline; } first && $7 ~ trig { printf "%s\n", first; exit }' log

Code:
|06:10:22.211| mymachine |2|     | kernel :|            RBL: RBL Code 10
|06:10:22.211| mymachine |1|     | kernel :|            DRPD: DRPD 789123
|06:10:22.211| mymachine |2|     | kernel :|            RTR: RTR Incomplete
|06:10:22.211| mymachine |2|     | kernel :|RunThread() - This is it BIOS-INFOXXX : Alert, get info on the upper part.


but with this log im getting negative results.

Code:
|06:10:22.201| mymachine |2|     | kernel :|            RBL: RBL Code 10
|06:10:22.201| mymachine |1|     | kernel :|            DRPD: DRPD 789123
|06:10:22.201| mymachine |2|     | kernel :|            RTR: RTR Incomplete
|06:10:22.211| mymachine |2|     | kernel :|RunThread() - This is it BIOS-INFOXXX : Alert, get info on the upper part.

How can i fix the script to match the timestamp "06:10:22.211" first then get the trigger value even though the timestamp different?

thanks in advance.

Last edited by zaxxon; 09-13-2011 at 04:49 AM.. Reason: added code tags for the line of code
# 2  
Old 09-13-2011
Your 2nd log file and pattern does not match! What is it that you really want?

--ahamed
# 3  
Old 09-13-2011
Try like..
Code:
awk -v t="06:10:22.2[01][01]" ...

# 4  
Old 09-14-2011
Hi Ahamed101,

Yes that is right, 2nd log file and pattern doesn't match but the 2nd log file is supposed to be what I really want to match and achieve.

How should I get results based on the 2nd log?

thanks.


Quote:
Originally Posted by ahamed101
Your 2nd log file and pattern does not match! What is it that you really want?

--ahamed
# 5  
Old 09-14-2011
May be this is what you want.

Code:
awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$7 ~ main { first = $0 } $2 ~ t && $7 ~ trig { printf "%s\n", first; exit }' log

If not, please explain it once more.

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 6  
Old 09-16-2011
Hi Ahamed, this one works for me. thanks a lot.

Quote:
Originally Posted by ahamed101
May be this is what you want.

Code:
awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$7 ~ main { first = $0 } $2 ~ t && $7 ~ trig { printf "%s\n", first; exit }' log

If not, please explain it once more.

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

2. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. UNIX for Advanced & Expert Users

Expertise advice required <<URGENT>>

:eek:i hav a shell script in my linux server, i want to execute it everyday once automatically without using cron tabs as i dont hav permission to create one. So wht sld i do??:confused: (1 Reply)
Discussion started by: Jay Thakkar
1 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. UNIX for Dummies Questions & Answers

With expertise in the shell I want to help necessary to resolve project and wish you

Hello to all of you my friends That your friend's new in this forum and Otnmy you to help me to solve this small-scale project I would be grateful to you too The URL for the file that explains that the project (1 Reply)
Discussion started by: دجحخهعدج
1 Replies

7. Shell Programming and Scripting

With expertise in the shell I want to help necessary to resolve project and wish you a happy life

Hello to all of you my friends That your friend's new in this forum and Otnmy you to help me to solve this small-scale project I would be grateful to you too The URL for the file that explains that the project os-lab-Search_projectFall2009.pdf (1 Reply)
Discussion started by: دجحخهعدج
1 Replies

8. Shell Programming and Scripting

Regexpr expertise required

Any experts on regular expressions out there, can you help me rationalise this? In this post: - https://www.unix.com/shell-programming-scripting/121977-writing-algorithm-recode-data-points-2.html I use the code: - tmp = $1 ; gsub(/00/, ".") ; $1 = tmp tmp = $1 ;... (2 Replies)
Discussion started by: steadyonabix
2 Replies

9. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

10. Solaris

x11vnc & tightvnc Expertise Required !

Hi all, For the past 3 days I have been struggling like :mad: to setup a VNC system between a solaris 8 unix host server and a windows XP tightvnc client viewer. Please bear in mind that the unix machine is crap & probably should be taken to the "Antiques Road Show on the BBC". Everything is... (2 Replies)
Discussion started by: fawqati
2 Replies
Login or Register to Ask a Question