Only print matching lines in perl from the command line -
i'm trying extract ip addresses file. far, i'm using
cat foo.txt | perl -pe 's/.*?((\d{1,3}\.){3}\d{1,3}).*/\1/'
but prints lines don't contain match. can fix piping through grep, seems ought unnecessary, , lead errors if regexes don't match perfectly.
is there simpler way accomplish this?
if you've got grep, call grep directly:
grep -po "(\d{1,3}\.){3}\d{1,3}" foo.txt
Comments
Post a Comment