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
sed
operates 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_Ms
to all those files before_1
and_2
? – beginner Sep 09 '23 at 14:25prename 's/_[12]\./_Ms&/g' *.gz
(orperl-rename
orrename
or 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' *.gz
works for me. You might want to double check whether yourrename
is 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"; done
no need of anyrename
ofperl-rename
– beginner Sep 09 '23 at 15:24