I have some symbolic linked files and some normal files like below:
P_2_UC34_31_1.gz
P_2_UC34_31_2.gz
P_2_UC34_32_1.gz
P_2_UC34_32_2.gz
P_2_UC34_33_1.gz
P_2_UC34_33_2.gz
P_2_UC34_31_1.gz and P_2_UC34_31_2.gz are symbolic links. The other 4 files are normal files (not symbolic links).
I'm trying to add _Ms before the _1 and _2 in all the files.
For the symbolic links I tried like below:
sed -i --follow-symlinks 's/_1/_Ms&/g' *.gz
But this didn't work. I didn't get any error and the file names are not changed.
I want the output to be like below:
P_2_UC34_31_Ms_1.gz
P_2_UC34_31_Ms_2.gz
P_2_UC34_32_Ms_1.gz
P_2_UC34_32_Ms_2.gz
P_2_UC34_33_Ms_1.gz
P_2_UC34_33_Ms_2.gz
sedoperates on the contents of files, not their names. You probably just ruined those gzip files irrecoverably (unless you have backups, which I hope you do). What you want is a tool for renaming, likeperl-rename(or whatever it is called in your OS) – muru Sep 09 '23 at 14:20_Msto all those files before_1and_2? – beginner Sep 09 '23 at 14:25prename 's/_[12]\./_Ms&/g' *.gz(orperl-renameorrenameor whatever it maybe). So you restored the files from backup? – muru Sep 09 '23 at 14:41rename 's/_[12]\./_Ms&/g' *.gz– beginner Sep 09 '23 at 14:48$&, not&.perl-rename 's/_[12]\./_Ms$&/g' *.gzworks for me. You might want to double check whether yourrenameis actually the Perl one or the util-linux one or something else altogether. – muru Sep 09 '23 at 14:51for file in *_1.gz; do mv "$file" "${file%_1.fq.gz}_Ms_1.fq.gz"; doneno need of anyrenameofperl-rename– beginner Sep 09 '23 at 15:24