Reputation: 179
I have files with such naming pattern:
S_1020_E_1293Person_using_PharmacyBasket.csv
S_1298_E_1365Reading instructions.csv
S_1368_E_1691Person_using_Phone.csv
S_136_E_155Other activity.csv
S_157_E_305Reading instructions.csv
S_1693_E_1850Reading instructions.csv
S_1855_E_1887Other activity.csv
S_1905_E_1985Person_making_Tea.csv
S_2125_E_2236Person_making_Tea.csv
S_23_E_135Other activity.csv
S_2901_E_3058Person_using_Phone.csv
S_3060_E_3085Other activity.csv
S_321_E_387Reading instructions.csv
S_3450_E_3470Other activity.csv
S_3473_E_3499Person_watering_Plant.csv
S_3501_E_3582Other activity.csv
S_392_E_418Other activity.csv
I want to rename them in a way that after the second digit groups an underline character appear e.g. S_1368_E_1691Person_using_Phone.csv
get renamed to S_1368_E_1691_Person_using_Phone.csv
is there such a command to do this ? the problem is that the number of digits are variable and also the number of words.
Upvotes: 0
Views: 52
Reputation: 15706
You can do this using the rename
utility which accepts a regular expression.
rename 's/^(S_\d+_E_\d+)/$1_/' *.csv
This assumes your files all start with something like "S_digits_E_digits".
Upvotes: 2
Reputation: 3613
This is easily done with perl (on the command line) and a regex to search and replace searching for the second numerical group. Maybe something like:
s/^(\D+\d+\D+d+)(.*?)$/\1_\2/
Upvotes: 0