Skip to main content
added 12 characters in body; edited title
Source Link
lcd047
  • 7.4k
  • 1
  • 24
  • 33

awk mach Awk: match exact string in line

I gavehave this file

a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z 

And I want to machmatch the exact string 200 using awk. soSo my resulresult should be

a deiauk Biking US 200 G 

Here's my code

awk -F ' ' '{if($(NF-1) ~ /200/){a[$1]++}}END{for (var in a){print a[var] " " var " " $(NF-1)}}' file.txt 

But after that I got all lines.

awk mach exact string in line

I gave this file

a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z 

And I want to mach exact string 200 using awk so my resul should be

a deiauk Biking US 200 G 

Here's my code

awk -F ' ' '{if($(NF-1) ~ /200/){a[$1]++}}END{for (var in a){print a[var] " " var " " $(NF-1)}}' file.txt 

But after that I got all lines

Awk: match exact string in line

I have this file

a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z 

And I want to match the exact string 200 using awk. So my result should be

a deiauk Biking US 200 G 

Here's my code

awk -F ' ' '{if($(NF-1) ~ /200/){a[$1]++}}END{for (var in a){print a[var] " " var " " $(NF-1)}}' file.txt 

But after that I got all lines.

Source Link
user3334375
  • 1.8k
  • 6
  • 17
  • 16

awk mach exact string in line

I gave this file

a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z 

And I want to mach exact string 200 using awk so my resul should be

a deiauk Biking US 200 G 

Here's my code

awk -F ' ' '{if($(NF-1) ~ /200/){a[$1]++}}END{for (var in a){print a[var] " " var " " $(NF-1)}}' file.txt 

But after that I got all lines