LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2018, 11:31 AM   #1
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Rep: Reputation: Disabled
AWK - filter value greater than


Hello,

I am trying to use awk commend to output the lines of file having 2nd column greater than 50. I have found similar thread for this and the suggestion given in that almost worked but having few issues.

For example
Code:
 awk -v x=50 '$2 >= x' latency-report.csv
Path       Latency
# node_path                                                                                         0
/FixedWireless/Alberta/Contempora/Site2-Weiss-Switcha                                               54
/FixedWireless/Alberta/Glenwood/Site1-GlenwoodPOP-BHa                                               137
/FixedWireless/Alberta/HeadEnd/DDV CiscoASA1                                                        52
/FixedWireless/BritishColumbia/DawsonCreek/Gateway                                                  81
/FixedWireless/BritishColumbia/DawsonCreek/Site1-FortSt.John-UPS                                    82
/FixedWireless/BritishColumbia/FortStJohn/Gateway                                                   78
/FixedWireless/BritishColumbia/FortStJohn/Site1-FortSt.John-CMM                                     80
/FixedWireless/BritishColumbia/FortStJohn/Site1-FortSt.John-CMMa                                    81
/FixedWireless/BritishColumbia/FortStJohn/Site1-FortSt.John-CMMb                                    80
/FixedWireless/BritishColumbia/FortStJohn/Site1-FortSt.John-CMMc                                    80
/FixedWireless/NewBrunswick/Hampton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2      3
/FixedWireless/NewBrunswick/Hampton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2a     0
/FixedWireless/NewBrunswick/Hampton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2b     4
/FixedWireless/NewBrunswick/Hampton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2c     4
/FixedWireless/NewBrunswick/Moncton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2a     3
/FixedWireless/NewBrunswick/Moncton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2b     0
/FixedWireless/NewBrunswick/Moncton/Site8-GardnerCreekBXI-Ciena Site8-RiverviewWTPOP-BHtoSite2      3
/FixedWireless/Ontario/Headend/DDV CiscoASA                                                         0
/FixedWireless/Ontario/TeraByteMeridian/Switch2-Main-Switch                                         529
/FixedWireless/Ontario/TeraByteMeridian/Site29-Drews-Switch                                         50
/FixedWireless/Ontario/TeraByteMeridian/Site30-AlbertaBeach-Switch                                  51
/FixedWireless/Ontario/TeraByteMeridian/Site31-Larry-Switch                                         567
/FixedWireless/Ontario/TeraByteMeridian/Site34-Acheson-Switch                                       50
/FixedWireless/Ontario/TeraByteMeridian/Site35-NewSareptia-Switch                                   50
/FixedWireless/Ontario/TeraByteMeridian/Site36-Ondrack-Switch                                       50
/FixedWireless/Ontario/TeraByteMeridian/Site37-RabbitHill-Switch                                    53
/FixedWireless/Ontario/Bradford/Site1-BradfordPOP-Ciena Site1-BrantfordPOP-Sector1                  4
/FixedWireless/Ontario/Bradford/Site1-BradfordPOP-Sector1 Site1-BrantfordPOP-Sector2                6
/FixedWireless/Ontario/Bradford/Site1-BradfordPOP-Sector2 Site1-BrantfordPOP-Sector3                0
/FixedWireless/Ontario/Bradford/Site2-Keswick Site2-BrantfordSouth-BHfrSite1                        7
/FixedWireless/Ontario/Bradford/Site2-Keswick Site2-BrantfordSouth-BHfrSite1b                       5
/FixedWireless/Ontario/Bradford/Site2-Keswick Site2-BrantfordSouth-BHfrSite1a                       5
/FixedWireless/Ontario/Brantford/Site1-BradfordPOP-Ciena Site1-BrantfordPOP-Sector1                 10
/FixedWireless/Ontario/Brantford/Site1-BradfordPOP-Sector1 Site1-BrantfordPOP-Sector2               10
/FixedWireless/Ontario/Brantford/Site1-BradfordPOP-Sector2 Site1-BrantfordPOP-Sector3               10
/FixedWireless/Ontario/Brantford/Site2-Keswick Site2-BrantfordSouth-BHfrSite1                       12
/FixedWireless/Ontario/Brantford/Site2-Keswick Site2-BrantfordSouth-BHfrSite1y                      9
/FixedWireless/Ontario/Pembroke/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPU               8
/FixedWireless/Ontario/Pembroke/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPUa              10
/FixedWireless/Ontario/Pembroke/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPUb              10
/FixedWireless/Ontario/Pembroke/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPUc              10
/FixedWireless/Ontario/Pembroke/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPUd              10
/FixedWireless/Ontario/Peterborough/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPUa          4
/FixedWireless/Ontario/Peterborough/Site1-PeterboroughPOP-Ciena Site1-PeterboroughPOP-NPU           4
/FixedWireless/Ontario/PortHope/Site4-GriffisCorner-Ciena Site4-Hampstead-NPU                       5
/FixedWireless/Ontario/PerthWiMAX/Site4-GriffisCorner-Ciena Site4-Hampstead-NPUa                    7
/FixedWireless/Ontario/PerthWiMAX/Site4-GriffisCorner-Ciena Site4-Hampstead-NPU                     7
/FixedWireless/Saskatchewan/Watson/Site1-WatsonPOP                                                  56
/FixedWireless/Saskatchewan/Watson/Site3-kylemoreb                                                  57
/FixedWireless/Saskatchewan/Yorkton/Site1-WatsonPOPa                                                60
[root@smokeping pradeeps]#
I dont understand why the above command doesnt filter properly. Any idea?
 
Old 07-04-2018, 11:34 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Because $2 is not always the column with number?
 
Old 07-04-2018, 11:38 AM   #3
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
It is always a number (including zero). Not sure why it shows numbers like 3.
 
Old 07-04-2018, 11:40 AM   #4
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
My bad i see what you mean. Let me try fixing it.
 
Old 07-04-2018, 11:41 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
No it's not always a number, verify:
Code:
awk '{print $2}' latency-report.csv
edit, see ?
 
Old 07-04-2018, 11:44 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by keefaz View Post
Because $2 is not always the column with number?
Take this line as an example:

Code:
/FixedWireless/Ontario/Headend/DDV CiscoASA                                                         0
If you are separating the fields with spans of whitespace, then the number you are looking for is in the third field not the second. If you have the luck to be dealing with tabs then set the Field Separator (FS) to be a tab. '[\t]'
 
Old 07-04-2018, 12:40 PM   #7
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Yes. I see that. Apologies for inconvenience. Thanks for looking into it.
 
Old 07-04-2018, 02:11 PM   #8
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
If the number is always the last column in the file then you can just use NF which represents the number of fields. From the awk manpage.

Quote:
The variable NF is set to the total number of fields in the input record.
Try
Code:
awk -v x=50 '$NF >= x' latency-report.csv

Last edited by tofino_surfer; 07-04-2018 at 02:14 PM. Reason: added reference
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk: filter out fields that are blank or are spaces schneidz Programming 18 04-08-2016 08:09 PM
[SOLVED] Using awk to filter output from the ls command lamont0 Linux - Newbie 10 04-04-2016 06:47 PM
awk filter & print Kropotkin Programming 1 12-01-2014 08:52 AM
[SOLVED] awk script to filter and delete crxlurp Linux - Newbie 6 07-05-2011 01:33 PM
Using sed or awk to filter a file mitchell2345 Linux - Software 3 04-10-2009 10:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration