Issue
I have a lot of files like "some_text some_number.jpg", for example:
blabla 1.ext
blabla 22.ext
blabla 323.ext
And I need to rename thies to "some_text some_number-some_number+1.jpg":
blabla 1-2.ext
blabla 22-23.ext
blabla 323-324.ext
How can I use \1 like integer variable?
Of couse this code is wrong:
for fn in *; do new_fn=$(echo $fn|sed 's/ \([0-9]*\)/ \1-\1\++/'); mv $fn $new_fn; done
blabla 1-1++.ext
blabla 22-22++.ext
blabla 323-323++.ext
Solution
How can I use \1 like integer variable?
It is impossible to use anything as integer in sed. It is impossible to do arithmetic operations in sed. Use something else. Bash, Python, Perl, etc.
Try, untested, however should give you a hint what algorithm you might want to implement:
for fn in *; do
# split on space and dot!
IFS=' .' read -r pre num post <<<"$fn"
newnum=$((num + 1))
echo mv "$fn" "$pre $newnum.$post"
done
Answered By - KamilCuk Answer Checked By - Marilyn (WPSolving Volunteer)