Issue
I have a list of subnets in a file for eg:
2.1.1.0/24
2.2.2.0/24
21.2.2.0/24
24.5.7.0/24
22.6.7.0/24
224.25.75.0/24
How can I grep and get the output only of the subnet having first octet 2. The desired output should be
2.1.1.0/24
2.2.2.0/24
I tried to use cat file | grep '^2'
but still I couldnt get the output as above. I get the whole file back.
Solution
Using grep
$ grep '^2\>' input_file
2.1.1.0/24
2.2.2.0/24
Answered By - HatLess Answer Checked By - Marilyn (WPSolving Volunteer)