bash removing part of a file name
rename
is part of the perl
package. It renames files according to perl-style regular expressions. To remove the dates from your file names:
rename 's/[0-9]{14}//' CombinedReports_LLL-*.csv
If rename
is not available, sed
+shell
can be used:
for fname in Combined*.csv ; do mv "$fname" "$(echo "$fname" | sed -r 's/[0-9]{14}//')" ; done
The above loops over each of your files. For each file, it performs a mv
command: mv "$fname" "$(echo "$fname" | sed -r 's/[0-9]{14}//')"
where, in this case, sed
is able to use the same regular expression as the rename
command above. s/[0-9]{14}//
tells sed
to look for 14 digits in a row and replace them with an empty string.