Renaming Filenames by replacing a part


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming Filenames by replacing a part
# 1  
Old 01-22-2014
Renaming Filenames by replacing a part

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
c_d_20140101

Could you please help to achieve this?

I have a set of 2000 files
# 2  
Old 01-22-2014
if rename works then
Code:
rename _2010 _2014 *2010*

# 3  
Old 01-22-2014
with sed,

Code:
ls *2010* | sed 's/\(.*\)_\([0-9]\{4\}\)\(.*\)/mv \1_\2\3 \1_2014\3/g'



Edit : This will print the mv oldfile newfile to the screen. You can redirect it to a file, take a look and if all ok, source the file with

Code:
. command_file

This User Gave Thanks to clx For This Post:
# 4  
Old 01-22-2014
thanks man for the support
# 5  
Old 01-22-2014
An approach using shell builtins:
Code:
for file in *_2010*
do
        mv "$file" "${file/_2010/_2014}"
done

This User Gave Thanks to Yoda For This Post:
# 6  
Old 01-22-2014
Another way:
Code:
ls *_2010*| sed -e "p;s/_2010/_2014/"|xargs -n2 mv

This User Gave Thanks to Klashxx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

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

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 cglogo tougl1953 dgmel bogd 01 -- ttgductoog ggdté gollogtd.ext1the others files needed to be renamed cglogo... (5 Replies)
Discussion started by: mc2z674gj
5 Replies

3. Shell Programming and Scripting

Change part of filenames in a bulk way

Hallo! I have generated lots of data file which all having this format: sp*t1overt2*.txt Now I want to change them in this way: sp*t2overt1*.txt The rest of the file names stay unchanged. I know this is kind of routine action in sed or awk, but dont know how! I tried this command: ... (6 Replies)
Discussion started by: forgi
6 Replies

4. 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

5. UNIX for Dummies Questions & Answers

renaming filenames

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)
Discussion started by: vpv0002
0 Replies

6. Shell Programming and Scripting

Renaming Movies (or Flipping Portions of Filenames Using sed or awk)

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)
Discussion started by: ksk
4 Replies

7. Shell Programming and Scripting

grepping a part of filenames

Hi , I have a list of files in a directory and filename format is as follows: PQ223390 PQ876912 PQ768901 PQ398140 and so on I want to grep the first four digits of all the files after PQ, into a file. Ex: 2233 8769 6890 3981 and so on Can anyone tell me the command? thankx jazz (11 Replies)
Discussion started by: jazz
11 Replies

8. Shell Programming and Scripting

renaming part of a file

I have file like this xxxx_yyyy.sh tttt_yyyy.sh aaaa_yyyy.sh how can I do that ? please help me thanks (2 Replies)
Discussion started by: ajaya
2 Replies

9. UNIX for Dummies Questions & Answers

Renaming of multiple filenames

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)
Discussion started by: shashi_kiran_v
4 Replies

10. UNIX for Dummies Questions & Answers

Renaming of multiple filenames

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)
Discussion started by: shashi_kiran_v
7 Replies
Login or Register to Ask a Question