I have 55 files named:
result_fresh_1.txt
...
result_fresh_55.txt
I want to rename them to:
result_bl_1.txt
...
result_bl_55.txt
how can I do this automatically?
I have 55 files named:
result_fresh_1.txt
...
result_fresh_55.txt
I want to rename them to:
result_bl_1.txt
...
result_bl_55.txt
how can I do this automatically?
for file in result_fresh_*.txt
do
mv "$file" $(echo "$file" | sed 's/_fresh_/_bl_/')
done
I have a Perl-based rename
command (also available on Linux machines, so that equivalent source must be available elsewhere too) that would reduce it to:
rename 's/_fresh_/_bl_/' result_fresh_*.txt
There aren't any spaces in the names shown, but the code would work sanely unless the names included newlines.
Try:
for f1 in $(echo {1..55});do
if [ -f "result_fresh_$f1.txt" ];then
mv result_fresh_$f1.txt result_b1_$f1.txt
fi
done