0

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?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

0
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.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

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
michael501
  • 1,452
  • 9
  • 18