How do I parse file with multiple different columns ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I parse file with multiple different columns ?
# 1  
Old 09-28-2012
How do I parse file with multiple different columns ?

I have a tool which generates results in a file at every minute and which has following columns.
I need to create a script checks this file constantly and if Column ( QOM ) has value more then "30S" it should send an email.
Can anybody help ?
Thansk a lot.


Code:
Time MxML MxQD G P OIC OUC MDC MEC UNC CQD PQF TQF TQE QOM OQTS OQTL
-------------------------------------------------------------------------------------------------------------------
15:12:34 20480000 200000 E E 0 0 1842853 1837403 0 0 0.00% 0.06s 0.01s

At any time some fields may be empty. In above example, TQF TQE QOM were blank.
In following example I have added some more parameters.

Column width is changing based on data.

In following line I want to track value "14s" , if that column is higher then
"30S" i need to send an email.

Code:
16:22:36 20480000 200000 E E 7 0 24 24 1 0 0.00% inf inf 14s 1.04s 0.25s

One more point, I always have last 3 columns ends with "s"
I need the value of third column from last.

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 09-28-2012 at 01:12 PM..
# 2  
Old 09-28-2012
Code:
awk '{if($(NF-2) ~ /s/){gsub("s","",$(NF-2));if($(NF-2) > 30){print }}}' file


Last edited by pamu; 09-28-2012 at 01:58 PM.. Reason: edited
This User Gave Thanks to pamu For This Post:
# 3  
Old 09-28-2012
Thank you. Some syntax errors

Thank you very much but I am hitting some syntax errors.
Code:
awk '$(NF-2) ~ /s/{gsub("s","",$(NF-2));if($(NF-2) > 30){print }}' timesheettest.log > /tmp/final1
awk: syntax error near line 1
awk: illegal statement near line 1


Last edited by Scott; 10-17-2012 at 10:35 AM.. Reason: Code tags
# 4  
Old 09-28-2012
Use nawk instead of awk.
This User Gave Thanks to elixir_sinari For This Post:
# 5  
Old 09-28-2012
cat timesheettest.log.2
Code:
16:32:36  20480000    200000 E E     9     0     147     193     1        47   0.02%  3d      14s   0.32s   0.21s

I tried nawk , it did not fail but did not gave me any results.

Code:
nawk '{if($(NF-2) ~ /s/){gsub("s","",$(NF-2));if($(NF-2) > 30){print }}}' timesheettest.log.2 > /tmp/log3

/tmp/log3 is empty.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!


---------- Post updated at 01:13 PM ---------- Previous update was at 01:06 PM ----------

Now it is good. I foggot to change value moer then 30S. I did that and now I get the results as full line. this will be good. thanks a lot.
I truly appreciate it.
Thanks again

Last edited by vgersh99; 09-28-2012 at 02:12 PM.. Reason: code tags, please!
# 6  
Old 09-28-2012
check your first post ...
if value is greater than 30s..
then only you want to send mail ....
try with more than 30 Smilie
This User Gave Thanks to pamu For This Post:
# 7  
Old 10-17-2012
Need help on awk

Hi Pamu,
Now I have to get the info on Minute from last 3rd columnd.

Code:
   03:08:53  20480000    200000 E E     6     0      22       0     1      2986   1.49%      2h   10m 501.45s  62.19s

I used the following to check the 3rd column from last is greater then 9 minute.
Code:
 nawk '{if($(NF-2) ~ /m/){gsub("m","",$(NF-2));if($(NF-2) > 9){print $(NF-2)}}}' /tmp/timesheets1.log

Somehow it does not seem to work.
Can you please help me ? Thx a lot.

Last edited by Scott; 10-17-2012 at 10:36 AM.. Reason: Use code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns

Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
Discussion started by: vikas_trl
7 Replies

2. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

3. Shell Programming and Scripting

Using awk to parse a file with mixed formats in columns

Greetings I have a file formatted like this: rhino grey weight=1003;height=231;class=heaviest;histology=9,0,0,8 bird white weight=23;height=88;class=light;histology=7,5,1,0,0 turtle green weight=40;height=9;class=light;histology=6,0,2,0... (2 Replies)
Discussion started by: Twinklefingers
2 Replies

4. Shell Programming and Scripting

Compare Multiple Columns in one file

Hello guys, I am quite new to Shell Scripting and I need help for this I have a CSV file like this: Requisition,Order,RequisitionLineNumber,OrderLineNumber REQ1,Order1,1,1 REQ1,Order1,1,3 REQ2,Order2,1,5 Basically what I want to do is compare the first 3 fields If all 3 fields are the same... (5 Replies)
Discussion started by: jeffreybsu
5 Replies

5. Shell Programming and Scripting

Printing multiple columns from a file

Hi, I need just to print the values of second and fourth column from a file # cat dispaly id Name Std Specialist 1 sss X mathematics 2 uyt IX geography 3 vcd X English i tried with some NF command.. I think am wrong.. Is there anyother way to print my requirement (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

6. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

7. Shell Programming and Scripting

Read multiple files, parse data and append to a file

Hi..Can anyone suggest a simple way of achieving this. I have several files which ends with extension .vcf . I will give example with two files In the below files, we are interested in File 1: 38 107 C 3 T 6 C/T 38 241 C 4 T 5 C/T 38 247 T 4 C 5 T/C 38 259 T 3 C 6 T/C... (8 Replies)
Discussion started by: empyrean
8 Replies

8. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

9. Shell Programming and Scripting

parse file into tab separated columns

Hello, I am trying to parse a file that resembles the last three groupings into something looking like the first two lines. I've fiddled with sed and awk a bit, but can't get anything to work properly. I need them separated by some delimiter. The file is some 23,000 lines of the stuff.... ... (9 Replies)
Discussion started by: dkozel
9 Replies

10. UNIX for Dummies Questions & Answers

sorting a file with multiple columns

I have a file with several columns: Column1 Column2 Column3. . .Column6 I want to sort the data from Column6. Could I do that through sort even if there are spaces in between fields? Much thanks! outta. (3 Replies)
Discussion started by: outtacontrol
3 Replies
Login or Register to Ask a Question