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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
07-04-2018, 11:31 AM
#1
Member
Registered: Oct 2015
Posts: 79
Rep:
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?
07-04-2018, 11:34 AM
#2
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552
Because $2 is not always the column with number?
07-04-2018, 11:38 AM
#3
Member
Registered: Oct 2015
Posts: 79
Original Poster
Rep:
It is always a number (including zero). Not sure why it shows numbers like 3.
07-04-2018, 11:40 AM
#4
Member
Registered: Oct 2015
Posts: 79
Original Poster
Rep:
My bad i see what you mean. Let me try fixing it.
07-04-2018, 11:41 AM
#5
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552
No it's not always a number, verify:
Code:
awk '{print $2}' latency-report.csv
edit, see ?
07-04-2018, 11:44 AM
#6
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Quote:
Originally Posted by
keefaz
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]'
07-04-2018, 12:40 PM
#7
Member
Registered: Oct 2015
Posts: 79
Original Poster
Rep:
Yes. I see that. Apologies for inconvenience. Thanks for looking into it.
07-04-2018, 02:11 PM
#8
Member
Registered: Aug 2007
Posts: 483
Rep:
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
All times are GMT -5. The time now is 02:40 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News