Visit The New, Modern Unix Linux Community


Renaming files & folder according to the similarities in filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming files & folder according to the similarities in filenames
# 1  
Renaming files & folder according to the similarities in filenames

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
Code:
cglogo tougl1953 dgmel bogd 01 -- ttgductoog ggdté gollogtd.ext1

the others files needed to be renamed
Code:
cglogo tougl1953 bogd 01.ext2

to
Code:
cglogo tougl1953 bogd 01 -- ttgductoog ggdté gollogtd.ext2

Code:
cglogo tougl1953 bogd 01.ext3

to
Code:
cglogo tougl1953 bogd 01 -- ttgductoog ggdté gollogtd.ext3

Code:
cglogo tougl1953 bogd 01.ext4

to
Code:
cglogo tougl1953 bogd 01 -- ttgductoog ggdté gollogtd.ext4

& a folder
Code:
cglogo tougl1953 bogd 01

to
Code:
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 !
# 2  
For files
1>First check with the below command if you are satisfied with the results
Code:
ls * | perl -lne '{$Tget=$_;s/\./ -- ttgductoog ggdté gollogtd./;print "$Tget"." <--TO--> "."$_";}'

2>If satisfied with what you got in first step execute for renaming
Code:
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>
Code:
 perl -lne '{$Tget=$_;s/$/ -- ttgductoog ggdté gollogtd/;print "$Tget"." <--TO--> "."$_";}'

2>
Code:
perl -lne '{$Tget=$_;s/$/ -- ttgductoog ggdté gollogtd/;rename "$Tget","$_";}'

This User Gave Thanks to msabhi For This Post:
# 3  
Code:
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

Code:
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 !
# 4  
You can change the text highlighted in red to your customized occurrence...
I hope i got your requirement right..
Quote:
Originally Posted by mc2z674gj
Code:
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

Code:
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 !
This User Gave Thanks to msabhi For This Post:
# 5  
i mean can i put a variable like t = text after " -- "
and put the variable in the code
Code:
perl -lne '{$Tget=$_;s/$/ -- variable t/;rename "$Tget","$_";}'


Last edited by mc2z674gj; 10-27-2012 at 04:09 AM..
# 6  
Quote:
Originally Posted by mc2z674gj
i mean can i out a variable like t = text after " -- "
and put the variable in the code
Code:
perl -lne '{$Tget=$_;s/$/ -- variable t/;rename "$Tget","$_";}'

Yes.
Code:
perl -lne '$myvar="some text";$Tget=$_;s/$/ -- $myvar/;rename "$Tget","$_";'

This User Gave Thanks to elixir_sinari For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #73
Difficulty: Easy
BSD (Berkeley Software Distribution) is an open-source, Unix-like operating system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming files with Spaces in Filenames

Entry level scripter. Any help appreciated. for file in *; do rename '4321_' '' $file ; done Doesn't work for files with spaces in between FOr eg 4321_1004.dat is renamed to 1004.dat but 4321_1004 2008.dat stays the same (1 Reply)
Discussion started by: davnavin
1 Replies

2. Shell Programming and Scripting

How to copy files with the same filenames as those in another folder to that same folder?

Hello All A similar question like this was asked before but I need to change part of the question. I've two folders, Folder A contains some image files in 150 subfolders; Folder B contains text files in 350 subfolders. All image files in Folder A have the same filename as the text... (5 Replies)
Discussion started by: chlade
5 Replies

3. UNIX for Dummies Questions & Answers

Renaming files in a folder

Hi, I have 1000 *.txt files in a folder and I would like to rename them data1.txt through data1000.txt. The order does not matter or the names of the initial input files. How would I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. UNIX for Dummies Questions & Answers

Renaming files in a folder

Hi, Hope someone can help... I'm pretty much new to unix and can only do basic commands. I have an issue where by every day I need to schedule a job to look in a folder with a name format of .IP. will be different each day (when the day is over the folder extension changes), and rename any... (5 Replies)
Discussion started by: Harsharan
5 Replies

5. Shell Programming and Scripting

Help with renaming files in folder

Hello, I want to rename more than 100 files. These files have "?" in there existing file name but I want to rename files to there first part before "?" token. I have tried using for loop but it isn't working so help following is the sample filename and for loop that am trying to use: example of... (3 Replies)
Discussion started by: ls_lrta
3 Replies

6. UNIX for Dummies Questions & Answers

Renaming multiple files in a folder

Hi All, I am trying to change the XML filename in a folder to the rootelement in the XML file. Example: TestMsg2010-10-19_20_20_54.xml <?xml version="1.0" encoding="utf-8" ?> <R1Msg TimeStamp="2010-10-19T08:49:08.000000Z> <TestRec> <ID>1000</ID> </TestRec> </R1Msg> Wanted to extract the... (8 Replies)
Discussion started by: sree_chari
8 Replies

7. Shell Programming and Scripting

mass renaming files with complex filenames

Hi, I've got files with names like this : _Some_Name_178_HD_.mp4 _Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi Goffytofansub_Some name 483_HD.avi And iam trying to rename it with a regular pattern. My gola is this : Ep 178.mp4 Ep 496.avi Ep 483.avi I've tried using sed with... (8 Replies)
Discussion started by: VLaw
8 Replies

8. Shell Programming and Scripting

renaming files in a folder

I splited a file into parts, then i wrote a script to convert the format of the file names to this: part1.dat part2.dat but I wonder why part.dat is also created knowing that the k variable starts from 1 rm -f part* $(split -b $1 file.1 part_) set k = 1 for i in $(ls part_*) do mv -f... (1 Reply)
Discussion started by: saman_glorious
1 Replies

9. UNIX for Advanced & Expert Users

Renaming all files in a folder

Guys, i need to replace a particular pattern in lots of files in a folder with another pattern . Is there any command line script I can use to do the functionality. Eg: aalex > ls green_1234_colour.max red_1234_pen.max yellow1234flower.max Need to replace the 1234 in the file name with 9876... (4 Replies)
Discussion started by: appualex
4 Replies

10. Shell Programming and Scripting

copy all files with the same filenames as those in another folder

Hi, all: I've got two folders, folder A contains some image files (say, 100 files) in .jpg format; folder B contains all description files (say, 500 files) in .txt format. All image files in folder A are able to find their corresponding description files in folder B. That is to say,... (3 Replies)
Discussion started by: jiapei100
3 Replies

Featured Tech Videos