Renaming multiple files with 2 consecutive periods within name

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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
This command:
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.
rename
add a comment |Â
up vote
0
down vote
favorite
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
This command:
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.
rename
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
This command:
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.
rename
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
This command:
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.
rename
edited Mar 7 at 16:54
Gilles Quenot
15.3k13448
15.3k13448
asked Mar 7 at 16:48
Suzan Kowalski
1
1
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Try this :
rename -n 's/../-/' ./*
The . character in regex, means any character, so it matches everything!
Remove -n when you are satisfied with your tests
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Try this :
rename -n 's/../-/' ./*
The . character in regex, means any character, so it matches everything!
Remove -n when you are satisfied with your tests
add a comment |Â
up vote
2
down vote
Try this :
rename -n 's/../-/' ./*
The . character in regex, means any character, so it matches everything!
Remove -n when you are satisfied with your tests
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Try this :
rename -n 's/../-/' ./*
The . character in regex, means any character, so it matches everything!
Remove -n when you are satisfied with your tests
Try this :
rename -n 's/../-/' ./*
The . character in regex, means any character, so it matches everything!
Remove -n when you are satisfied with your tests
edited Mar 7 at 17:14
answered Mar 7 at 16:55
Gilles Quenot
15.3k13448
15.3k13448
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428797%2frenaming-multiple-files-with-2-consecutive-periods-within-name%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password