I have an input file:
class 1 3 5 10.10.10..0/23 hicks jimmy
class 3 10.12.10.0/22 mike
class.019283 10.10.15.10/20 henry
gym.847585 45 192.168.10.0/22 nancy jim steve maya
The output should look like this:
10.10.10..0/23
10.12.10.0/22
10.10.15.10/20
192.168.10.0/22
I have the following but it only prints the ip address
perl -lne 'print $& if /(\d+\.){3}\d+/' file
Regards,
egrep -o '[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/[0-9]+' inputfile
Yoda
3
I see two periods .
in your first line, not sure if that is valid:
10.10.10..0/23
10.12.10.0/22
10.10.15.10/20
192.168.10.0/22
But if that is valid and if you really want that in output:
awk '{match($0, /[0-9]+\.[0-9]+\.[0-9]+\.*[0-9]+\/[0-9]+/); print substr($0, RSTART, RLENGTH)}' file
Use /usr/xpg4/bin/awk
or nawk
in Solaris.
The code does work in Solaris. -o option
---------- Post updated at 11:41 AM ---------- Previous update was at 11:32 AM ----------
The second period is a typo. sorry
---------- Post updated at 11:42 AM ---------- Previous update was at 11:41 AM ----------
Thank you. it works
1 Like