I've a file ./123bar/foo.txt which has:
pro := text
ver := 1.0
rev := 2
and two env variables:
var =2.1
var2=3
I want to replace all ver with $var and rev with $var2. Expected output:
pro := text
ver := 2.1
rev := 3
I'm trying below to first find all the files with find and grep and then pass it to sed to achieve the result.
Below is the command I'm running:
find . -name 'foo.txt' | grep -P "\/[0-9]{3}bar" | xargs -I{} sed -E "s/:= *[0-9]+\.[0-9]+ *$/:= $var/g" -E "s/:= [0-9]+ *$/:= $var2/g" {}
it's not working and giving me error:
sed: can't read s/:= [0-9]+ *$/:= 3/g: No such file or directory
pro := text
ver := 2.1
rev := 45
How do I fix it? A neater/simpler solution is also welcome.