Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering Numbers In An Alphanumeric Field 1

Status
Not open for further replies.

rochejmike

Technical User
Nov 18, 2011
2
US
x,x,5428,x,5443,x,1,2,'Cable Depth : 10.8 m : S13 : Rx-grp
x,x,5444,x,5445,x,1,2,'Cable Depth : 10.8 m : S13 : Rx-grp
x,x,5434,x,5447,x,509,521,'Cable Depth : 10.6 m : S06 : Rx-grp
x,x,5443,x,5447,x,71,73,'Cable Depth : 10.9 m : S18 : Rx-grp
x,x,5401,x,5448,x,1,16,'Cable Depth : 10.4 m : S01 : Rx-grp
x,x,5446,x,5451,x,1,1,'Cable Depth : 10.9 m : S13 : Rx-grp

The above is an excerpt for a text file that I am trying to filter. What I need is to list out any lines with numbers in the first field seperated by colon's (10.8 m 10.6 m etc) where the numer is greater than 13.5 and less than 10.5. I suspect the 'm' is getting in the way of the filter ? What I have so far is

awk 'BEGIN {FS=":"} $2 ~ ($2 >= 11.5 ) {print} ' FILE.txt

but the result I get doesnt match what I know the correct number of entries to be. Any thoughts ?

Regards
 
Hi

Just remove what is not part of the number :
Code:
awk -F: '[teal]{[/teal]n[teal]=[/teal][navy]$2[/navy][teal];[/teal][COLOR=chocolate]gsub[/color][teal]([/teal][fuchsia]/[^0-9.]/[/fuchsia][teal],[/teal][green][i]""[/i][/green][teal],[/teal]n[teal])[/teal][teal]}[/teal]n[teal]>[/teal][purple]13.5[/purple][teal]||[/teal]n[teal]<[/teal][purple]10.5[/purple]' FILE.txt
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].


Feherke.
 
blindingly obvious now that you state it like that, that seems to do the job prefectly, just need to test it on some of the bigger files but thanks fella, really appreciate the quick response
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top