Hi! I have a string like this:
I want to be able to search that string and only display the 192.168.2.* entries. How can I accomplish this in Linux? I will not know ahead of time how many entries there are or what order they go in. In my example, 192.168.1.122 is the third string, but it might not always be.
I have tried, unsuccessfully:
This shows the entire line, including the 192.168.1.122. I need the line minus the 192.168.1.122
This has the same effect as the grep command.
This is close, but obviously only prints the first string found. Looping through the variables doesn't help either, because at least one of them will contain the strings I do not want (192.168.1.122 in my example).
I am sure there is a way to accomplish this, but I am having trouble finding it.
Code:
192.168.2.2 192.168.2.3 192.168.1.122 192.168.2.4 192.168.2.5 192.168.2.6
I have tried, unsuccessfully:
Code:
cat fake_ips | grep "192.168.2."
Code:
cat fake_ips | awk '/192.168.2./'
Code:
cat fake_ips | awk '/192.168.2./ {print $1}'
I am sure there is a way to accomplish this, but I am having trouble finding it.
Comment