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 ?
# 8  
Old 10-17-2012
What is result of below commands..?

Code:
nawk '{if($(NF-2) ~ /m/){gsub("m","",$(NF-2));if($(NF-2) > 9){print }}}' /tmp/timesheets1.log

nawk '{print $(NF-2)}' /tmp/timesheets1.log


Last edited by pamu; 10-17-2012 at 12:43 PM..
# 9  
Old 10-17-2012
Result=44m

One more point, requirement is also changed.

3rd column from last , gives me values ending in s, m and h.

I need to compare the value of 3rd column is ending with m.

If it is ending with s or h I need to ignore.
# 10  
Old 10-17-2012
Quote:
Originally Posted by jayeshpatel
Result=44m

One more point, requirement is also changed.

3rd column from last , gives me values ending in s, m and h.

I need to compare the value of 3rd column is ending with m.

If it is ending with s or h I need to ignore.
Yes. It will ignore values which doesn't has m in it..

This should work. I am not getting what could be the problem..

Code:
nawk '{if($(NF-2) ~ /m/){gsub("m","",$(NF-2));if($(NF-2) > 9){print $(NF-2)}}}' /tmp/timesheets1.log

# 11  
Old 10-17-2012
Now the recent command you send does not give me any values.

When I run 2 command separately you gave me before I get 44m.

If I use the the command ( the first one for thread you gave me ) for "s" to check for seconds , everythign works great. so I am not sure what is going wrong here with this "m" part.
# 12  
Old 10-18-2012
Quote:
Originally Posted by jayeshpatel
Now the recent command you send does not give me any values.

When I run 2 command separately you gave me before I get 44m.

If I use the the command ( the first one for thread you gave me ) for "s" to check for seconds , everythign works great. so I am not sure what is going wrong here with this "m" part.
Its working fine here. Please check..

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

$ awk '{if($(NF-2) ~ /m/){gsub("[A-z]","",$(NF-2));if($(NF-2) > 9){print $(NF-2)}}}' file2
10

$  awk '{if($(NF-2) ~ /m/){gsub("m","",$(NF-2));if($(NF-2) > 9){print $(NF-2)}}}' file2
10

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