I need to use the rename command to rename hundreds of files which contain .. (2 periods) within the filename and change .. to - (hyphen). The fact that it contains periods seems to be confusing the rename command.
Here are some example filenames:
20180201_190000_TX_AJAX..HHE_instrument_0456 20180201_190000_TX_AJAX..HHN_instrument_0456 20180201_190000_TX_AJAX..HHZ_instrument_0456
I need to rename these files to look linke:
20180201_190000_TX_AJAX-HHE_instrument_0456 20180201_190000_TX_AJAX-HHN_instrument_0456 20180201_190000_TX_AJAX-HHZ_instrument_0456
rename 's/../-/' *
results in these filenames:
-180201_190000_TX_AJAX..HHE_instrument_0456 -180201_190000_TX_AJAX..HHN_instrument_0456 -180201_190000_TX_AJAX..HHZ_instrument_0456
It seems that periods have some special purpose so it's getting confused. I then tried this:
rename 's/..H/-H/' *
The AJAX in the sample represents a station and these vary. The above syntax works and results in "20180201_190000_TX_AJAX-HHE_instrument_0456" as expected for many stations but unexpected results for others:
20180201_000000_SA.AKHBR..HNE_instrument_0542 renamed as 20180201_000000_SA.-HBR..HNE_instrument_0542 20180201_000000_SA.KSHB4..HHE_instrument_0935 renamed as 20180201_000000_SA.-HB4..HHE_instrument_0935 20180201_000000_SA.HTM01..HHE_instrument_0933 renamed as 20180201_000000_S-HTM01..HHE_instrument_0933
It seems any station which contains the letter H gets confused.
For some reference, AJAX is a station code, and station codes are either 4 or 5 characters in length.
Next I tried this:
rename ‘s/SA.????..H/SA.????-H/ * -n
but this generates an error:
"Nested quantifiers in regex; marked by <-- HERE in m/SA.??? <-- HERE ?..H/ at (eval 1) line 1."
so I guess it doesn't like wildcards.
Any help you can provide is appreciated.