string - Perl and Regex - single line mode matching -


why doesn't

perl -ne "print if /(<conn)([\s|\s]+?)(>)/sg;" /path/to/file 

match

<connector port="port" protocol="http/1.1" sslenabled="true"            maxthreads="150" scheme="https" secure="true"            clientauth="false" sslprotocol="tls" />` 

when match

<connector port="port" protocol="ajp/1.3" redirectport="port" /> 

and need match both same regex?

the -n option reads file line-by-line, can alter line whole file undefining input line terminator. that's done using local $/;, or using command line option -0777 follows:

perl -0777ne 'print "$1\n" while /(<conn.+?>)/sg;' /path/to/file 

it reads in whole file @ once. if that's problem, try setting $/ > (since pattern ends in >) or -o076 on command-line:

perl -076ne 'print "$1\n" if /(<conn.+?>)/sg;' /path/to/file 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -