How to emulate grep -o option in perl.
I mean to print not all line, only the exact match.
echo "2A2 BB" | perl -ne 'print if /2A2/'
2A2 BB
I want to print only 2A2.
How to emulate grep -o option in perl.
I mean to print not all line, only the exact match.
echo "2A2 BB" | perl -ne 'print if /2A2/'
2A2 BB
I want to print only 2A2.
echo "2A2 BB" | perl -ne 'print $1 if /(2A2)/'
or
echo "2A2 BB" | perl -ne 'print $1,"\n" if /(2A2)/'
if you want it newline terminated
Or:
zsh-4.3.9[sysadmin]% echo 2A2 BB|perl -lne'print/(2A2)/'
2A2