in my bash script i look for text inside a file and replace it with a variable from my bash script. I couldn't get the variable to be recognized by the perl command. any ideas?
mybash.bash:
#! /bin/sh
let "myNum=2"# myNum could be any integer
perl -pi -e 's/ABCD\d/ABCD$myNum/g' ./textfile.txt
textfile.txt:
'ABCD0' gets replace with 'ABCD' with above script
Use double quotes so as to enable interpolation of variables:
perl -pi -e "s/ABCD\d/ABCD$myNum/g" ./textfile.txt
^^^ ^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With