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.