Hi,
I have a list of IP, eg :
192.168.0.15
192.168.0.24
192.168.2.110
192.168.2.200
And I would like the shortest pattern who match with '192.168.0' and '192.168.2' (without the last dot and number).
Hi,
I have a list of IP, eg :
192.168.0.15
192.168.0.24
192.168.2.110
192.168.2.200
And I would like the shortest pattern who match with '192.168.0' and '192.168.2' (without the last dot and number).
perl -lane 'print $_ if $_=~/192.168.[02]/' filename.txt
grep '^192\.168\.[02]\.' file
or
grep -w '^192\.168\.[02]' file
Thanks itkamaraj,
To be honest i'm not very familiar with Perl in command line, I intended to use grep.
And i'm searching for something very generic, because I won't to read first numbers each time.
Something like this:
grep -P '\d+\.\d+\.\d+' filename.txt
My question is there a simpler pattern for this ?
Is possible to repeat some part of the pattern, for example: '\d+' x3 and '\.' x2
Like this?
grep -E '[0-9]{3}\.[0-9]{3}\.[02]\.' inputfile
Yes thanks that's the idea, but the question it's for Perl regex not POSIX.
Like this?
(\d{1,3}\.){3}
or this?
(\d+\.){3}
Yes, except that the part of IP should end with a number not a dot.