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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -