I have several files containing this line
Release: X
I want to increment X in all the files.
If X was constant between the files, I could have a bash script looping around the files and doing ($1 containing the former release number and $2 the new one, ie. $1 + 1) :
sed 's/Release: '$1'/Release: '$2'/' <$file >$file.new
Now, how should I do if the release number is different between files ?
Is it doable with sed ?
should I use another tool ?
Use awk
- it's exactly the right tool for this:
awk '/Release: [0-9]+/ { printf "Release: %d\n", $2+1 }' < $file > $file.new
Translation:
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