rename so that dot (.) is replaced with underscore (_)
1
0
Entering edit mode
2.1 years ago
arshad1292 ▴ 110

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 • 646 views
ADD COMMENT
1
Entering edit mode
2.1 years ago
5heikki 11k

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
ADD COMMENT
0
Entering edit mode

Thank you for your help!

ADD REPLY

Login before adding your answer.

Traffic: 1528 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6