I've got files with names like this :
[Various-PC3]_Some_Name_178_HD_[e2813be1].mp4
[TTB]_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 substitution expressions :
the result is
One file correctly renamed :-/
This one :
Went wrong with the first one
Then I tried perl. But considering that I have very few knowledges in it, I spent many time on my script
for an unexpected result :
I've also tried some alternatives of the beginning :
result
This one :
gave me
Any idea on how to reach my goal ?
Thx in advance !
Last edited by VLaw; 02-11-2011 at 04:25 PM..
Reason: Details of 1st bash script
You want more of an assembly line, not command calls for one file:
Review before executing! You might take all the files for one dir and do them at once in the background (parallel), just wrap lines for each dir in parens with amp: (...)& More than one process renaming in the same dir makes for file contention.
I don't know the answer to your question/problem, but in my experience, using 'ls' with a 'for' statement is just bad practice and even more so with spaces in your filenames. I would direct you to use the 'find' command.
Oh, extracted numbers! Sure. I never use -e on sed, just pile the lines on the command line, but with pretty spacing, sed on sed lines and shell on shell lines. You, too, deserve readable code and a lower error rate!
Still a lot of mv fork() and exec(), so PERL might have an advantage, assuming it knows how to rewrite directories internally. In C or PERL, you link() the file to the new name and unlink() it from the old name.
BTW, directories never shrink, so making new directories is not a bad idea. Big directories can waste a lot of time.
I strongly advise that you hide these filenames from Shell and avoid trying to put them into Shell environment variables. Try to work with external commands only.
Use unix "find" to generate a list of filenames into a file.
Then create a "sed" file containing your "sed" commands. Because Shell will not see them we only need to escape characters where "sed" requires it (which it will with some of these filenames!).
Run with the outline syntax:
Throughout this exercise we must avoid Shell seeing the 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)
Hi,
I have little experience on Shell scripts, I searched the forum but couldn't make out what I want.
I want to rename a set of files to a new file name
a_b_20100101
c_d_20100101
.......................
......................
I want to rename the files to
a_b_20140101... (5 Replies)
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.ext1the others files needed to be renamed
cglogo... (5 Replies)
I am a biologist and using an program on a computer cluster that generates a lot of data. The program creates a directory named
ExperimentX (where X is a number) that contains files "out.pdb" and "log.txt". I would like to create a script that renames the out.pdb file to out_ExperimentX.pdb (or... (1 Reply)
I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (0 Replies)
Hey folks
My problem is simple. For my first stash of movies, I used a naming convention of YEAR_MOVIE_NAME__QUALITY/ for each movie folder. For example, if I had a 1080p print of Minority Report, it would be 2002_Minority_Report__1080p/.
The 2nd time around, I changed the naming convention... (4 Replies)
Hi :)
Is there any command I could use to rename a bunch of files resident of the same location to their original name plus a fixed text string of my own?
Example:
File1
File2
File3
Output:
File1.txt
File2.txt
File3.txt
This is easy using a "for" loop but what I want is a one-line... (5 Replies)
Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ?
I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them.
Also, can... (1 Reply)
Hi All,
I need to rename the multiple file names.
I need to rename for example as follows
bas100e1_jun05 to FLAT1
bas100e2_jun05 to FLAT2
bas100e18_jun05 to FLAT18
Please not that I can cut_jun05 from the filename. Madhan had helped with a similar kind of script. But this is a new... (4 Replies)
Hi All,
I need to rename the file names.
I need to rename for example as follows
file001 to flat1
file100 to flat100
Thanks
Shash :confused: (7 Replies)