Dear all,
I would like to rename specific character all multiple file name at once as following example.
In original file name is ;
- file1_before.tsv
- file2_before.tsv
- file3_before.tsv
I want to change with only one command line without losing data as follow;
- file1.tsv
- file2.tsv
- file3.tsv
I'm very appriciate your idea and request for your suggestion.
Thank you very much.
According to your example, the below command will work!
# rename _before '' file?_before.tsv
@Nyi_Nyi_Lwin wrote:Dear all,
I would like to rename specific character all multiple file name at once as following example.
In original file name is ;
- file1_before.tsv
- file2_before.tsv
- file3_before.tsv
I want to change with only one command line without losing data as follow;
- file1.tsv
- file2.tsv
- file3.tsv
I'm very appriciate your idea and request for your suggestion.
Thank you very much.
Similarly to Noel's excellent rename-based answer, you could use shell parameter expansion to accomplish the same result:
for filename in file?_before.tsv; do mv -- "$filename" "${filename%_before.tsv}.tsv"; done
This "one-liner" loops over any/all filenames matching the "file?_before.tsv" pattern. There's only one command inside the loop -- the "mv" to rename each file in turn. The target filename is generated by removing the text "_before.tsv" from the end of the filename and then appending ".tsv" back to the end. I've used "--" to tell "mv" that there are no further options, as a generic safety principle in case you use a similar command in the future where filenames potentially begin with dashes and get mistakenly confused as options to mv.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.