I've been following the guidance here: Extract Substring Using RegExp in Plain Bash
I can't seem to get my code to work properly:
This echoes correctly:
for filename in ./unsent_xmls/*.xml; do
echo $filename | perl -lne 'print $& if /(\d{4})(?=-)/'
done
but when I try this it prints an empty result:
for filename in ./unsent_xmls/*.xml; do
package=$filename | perl -lne 'print $& if /(\d{4})(?=-)/'
echo $package
done
I've tried a number of different iterations.
perlcommand supposed to do? There's almost certainly a simpler way to do this inbashalone.perlalone :). But that perl matches the RE. If it matches, it prints "The string matched by the last successful pattern match". (Which is what$&means)