How to use awk to extract a line with exact match

awk, grep, match, regex, string-comparison

Solution

To do a full line regular expression match you need to anchor at the beginning and the end of the line by using `^` and `$`:

$ awk '/^hello10$/' test.txt
hello10

But you're not actually using any regular expression features beside the anchoring we just added which means you actually want plain old string comparison:

$ awk '$0=="hello10"' test.txt
hello10

Problem

How do I use awk to search for an exact match in a file? ``` test.txt hello10 hello100 hello1000 ``` I have tried the following and it returns all 3 lines ``` awk '$0 ~ /^hello10/{print;}' test.txt ``` grep -w hello10 does the trick but on this box grep version is very limited and only few switches available

Original source