use awk pick value from lines as condition for grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use awk pick value from lines as condition for grep
# 1  
Old 06-24-2010
use awk pick value from lines as condition for grep

Hi Folks!
I have a file like this

Code:
000000006    dist:0.0    FILE ./MintRoute/MultiHopWMEWMA.nc LINE:305:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:733 TEID:758
000000000    dist:0.0    FILE ./Route/MultiHopLEPSM.nc LINE:266:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:601 TEID:626

000000001    dist:0.0    FILE ./WSN-simulator-1.0/gnuplot_i_c.nc LINE:217:3 NODE_KIND:65 nVARs:5 NUM_NODE:66 TBID:375 TEID:401
000000002    dist:0.0    FILE ./WSN-simulator-1.0/gnuplot_i_c.nc LINE:378:3 NODE_KIND:65 nVARs:5 NUM_NODE:66 TBID:648 TEID:674

000000000    dist:0.0    FILE ./Drain/DrainLinkEstM.nc LINE:559:5 NODE_KIND:65 nVARs:8 NUM_NODE:85 TBID:819 TEID:850
000000001    dist:0.0    FILE ./Drain/DrainLinkEstM.nc LINE:580:5 NODE_KIND:65 nVARs:8 NUM_NODE:85 TBID:919 TEID:950

000000001    dist:0.0    FILE ./WSN-simulator-1.0/runLeach_c.nc LINE:137:4 NODE_KIND:65 nVARs:6 NUM_NODE:60 TBID:562 TEID:584
000000002    dist:0.0    FILE ./WSN-simulator-1.0/runLeach_c.nc LINE:209:4 NODE_KIND:65 nVARs:6 NUM_NODE:60 TBID:799 TEID:821
000000004    dist:0.0    FILE ./WSN-simulator-1.0/runMyalgo_c.nc LINE:252:4 NODE_KIND:65 nVARs:6 NUM_NODE:60 TBID:947 TEID:969
000000005    dist:0.0    FILE ./WSN-simulator-1.0/runMyalgo_c.nc LINE:314:4 NODE_KIND:65 nVARs:6 NUM_NODE:60 TBID:1101 TEID:1123

I want to grep the lines where the second number after "LINE" is greater then e.g. >=4. And the blocks should stay separated with a blank line. Can someone help?
# 2  
Old 06-24-2010
Code:
nawk 'NF{split($5,a,":"); k=(a[3]>=4)?1:0} !NF ||k' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 06-24-2010
GREAT!! Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

awk to reformat lines based on condition

The awk below uses the tab-delimeted fileand reformats each line based on one of three conditions (rules). The 3 rules are for deletion (lines in blue), snv (line in red), and insertion (lines in green). I have included all possible combinations of lines from my actual data, which is very large.... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to capture lines that meet either condition

I am trying to modify and understand an awk written by @Scrutinizer The below awk will filter a list of 30,000 lines in the tab-delimited file. What I am having trouble with is adding a condition to SVTYPE=CNV that will only print that line if CI=,0.95: portion in blue in file is <1.9. The... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

I have this list of files . Now I will have to pick the latest file based on some condition

3679 Jul 21 23:59 belk_rpo_error_**po9324892**_07212014.log 0 Jul 22 23:59 belk_rpo_error_**po9324892**_07222014.log 3679 Jul 23 23:59 belk_rpo_error_**po9324892**_07232014.log 22 Jul 22 06:30 belk_rpo_error_**po9324267**_07012014.log 0 Jul 20 05:50... (5 Replies)
Discussion started by: LoneRanger
5 Replies

5. Shell Programming and Scripting

Pick first "code" only [ grep/awk ]

All I have a requirement to search and pick the data as below. Explained with example. 38999|4812 Highway 52 North|Rockville|55901|0196 67541|2800 Dexter Road|Northville|38999|0196 This is pipe separate data. First column represents dealer id and 4th column represents the zip code where... (4 Replies)
Discussion started by: ak835
4 Replies

6. UNIX for Dummies Questions & Answers

Grep certain lines with condition

file input aaaa,52C aaaa,50C bbbb,50C bbbb,58C aaaa,52C bbbb,50C aaaa,30C bbbb,58C cccc,60C i want to print uniq lines with its max value of column2 expected output aaaa,52C bbbb,58C cccc,60C tks (4 Replies)
Discussion started by: radius
4 Replies

7. Shell Programming and Scripting

Where condition in grep or awk?

Dear All, I need help.. I am having a csv file. Home_TITLE,People_TITLE,Repo_ALIAS HMN5530,RKY5807,/mine_repo/rike001 HMN5530,SRY6443,/mine_repo/rike001 HMN5530,ARDY001,/mine_repo/rike001 If i have two value in varible RKY5807, HMN5530. how can fetch and store another value... (6 Replies)
Discussion started by: yadavricky
6 Replies

8. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

9. Shell Programming and Scripting

perl or awk remove empty lines when condition

Hi Everyone, # cat 1 a b b cc 1 2 3 3 3 4 55 5 a b (2 Replies)
Discussion started by: jimmy_y
2 Replies

10. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies
Login or Register to Ask a Question