This is a test version of Biostars. For the public version, visit https://www.biostars.org.
rename so that dot (.) is replaced with underscore (_)

Hello,

I have 500 files named like this:

A_694407.bin.21_fixed.db
B_069142.bin.2_fixed.db
O_1069121_S345.bin.22_fixed.db

I want to rename them so they look like this:

A_694407_bin21_fixed.db
B_069142_bin2_fixed.db
O_1069121_S345_bin22_fixed.db

Please let me know if you can write a script for that please

Thank you in advance!

rename linux mv

1 answer

With a variable:

for f in *.db; do n=$(basename "$f" .db | tr "." "_"); mv "$f" "$n".db; done 

Without a variable:

for f in *.db; do mv "$f" "$(basename "$f" .db | tr "." "_")".db; done

Log in to answer this question.