hello
does someone want to help me for this one ?
i want to rename files & a folder according to the similarities in filenames
for example :
the file with the good name
cglogo tougl1953 dgmel bogd 01 -- ttgductoog ggdt� gollogtd.ext1
the others files needed to be renamed
cglogo tougl1953 bogd 01.ext2
to
cglogo tougl1953 bogd 01 -- ttgductoog ggdt� gollogtd.ext2
cglogo tougl1953 bogd 01.ext3
to
cglogo tougl1953 bogd 01 -- ttgductoog ggdt� gollogtd.ext3
cglogo tougl1953 bogd 01.ext4
to
cglogo tougl1953 bogd 01 -- ttgductoog ggdt� gollogtd.ext4
& a folder
cglogo tougl1953 bogd 01
to
cglogo tougl1953 bogd 01 -- ttgductoog ggdt� gollogtd
so the file in "ext.1" is the good name and i want to rename others files and the folder with the similarities in filenames
thanks for you help !
msabhi
2
For files
1>First check with the below command if you are satisfied with the results
ls * | perl -lne '{$Tget=$_;s/\./ -- ttgductoog ggdt� gollogtd./;print "$Tget"." <--TO--> "."$_";}'
2>If satisfied with what you got in first step execute for renaming
ls * | perl -lne '{$Tget=$_;s/\./ -- ttgductoog ggdt� gollogtd./;rename "$Tget","$_";}'
---------- Post updated at 11:34 AM ---------- Previous update was at 11:31 AM ----------
FOR FOLDERS
use the below like how you used for files
1>
perl -lne '{$Tget=$_;s/$/ -- ttgductoog ggdt� gollogtd/;print "$Tget"." <--TO--> "."$_";}'
2>
perl -lne '{$Tget=$_;s/$/ -- ttgductoog ggdt� gollogtd/;rename "$Tget","$_";}'
1 Like
ls * | perl -lne '{$Tget=$_;s/\./ -- ttgductoog ggdt� gollogtd./;rename "$Tget","$_";}'
this script works perfectly for files, how can i change the occurrence "ttgductoog ggdt� gollogtd"
when this occurrence change
perl -lne '{$Tget=$_;s/$/ -- ttgductoog ggdt� gollogtd/;rename "$Tget","$_";}'
i'm unfamiliar with perl i don't know what's not working for the folder
thanks in advance !
msabhi
4
You can change the text highlighted in red to your customized occurrence...
I hope i got your requirement right..
1 Like
i mean can i put a variable like t = text after " -- "
and put the variable in the code
perl -lne '{$Tget=$_;s/$/ -- variable t/;rename "$Tget","$_";}'
Yes.
perl -lne '$myvar="some text";$Tget=$_;s/$/ -- $myvar/;rename "$Tget","$_";'
1 Like