Visit Our UNIX and Linux User Community


Multiple file rename (change in filename in unix with single command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple file rename (change in filename in unix with single command
# 1  
Old 11-08-2010
Java Multiple file rename (change in filename in unix with single command

Dear All,

Please help !

i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name ..

pls help..
# 2  
Old 11-08-2010
I am not sure if it can be done in a single unix command, but this small script may help you
Code:
#!/usr/bin/ksh

for k in PMC*.arc
do
   newfilename=`echo $k | sed 's/1//g'`
   cp $k $newfilename && rm $k
done

# 3  
Old 11-08-2010
MySQL

Thanks Dear it is working fine. but it is also remove one more char. form line

like PMC1_194_732756742.arc to PMC_94_732756742.arc here i need PMC1 will be rename by PMC only in next where _194_ need to be same as shown here
# 4  
Old 11-08-2010
try this,

Code:
ls PMC1*.arc | while read k; do cp $k `echo $k |sed 's/\(.*\)1_\(.*\).arc/\1_\2\.arc/g'` && rm $k; done

# 5  
Old 11-09-2010
thanks but still my problem is not resolve as i want PMC1_194_732756742.arc to PMC_1_194_732756742.arc here it is PMC_194_732756742.arc

can any one help me?
# 6  
Old 11-09-2010
Hi,

In your previous post it was not mentioned.

try this,
Code:
ls PMC1*.arc | while read k; do cp $k `echo $k |sed 's/\(.*\)1_\(.*\).arc/\1_1_\2\.arc/g'` && rm $k; done

# 7  
Old 11-09-2010
Hi praveen thansk it is done only few rows which has no like PMC1_241_*.arc ,PMC1_251_*.arc,PMC1_261_*.arc

get repalce with PMC_1_24_*.arc rest all are ok thanks

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

2. Shell Programming and Scripting

Filename rename with characters of file

Hi, I need a bit of help. I've used awk to get the first 7 characters of a file - awk '{print substr($0,0,7)}' test.csv How do I now take this variable to rename test.csv to variable.csv ? Any help or advice would be greatly appreciated! (2 Replies)
Discussion started by: sianm
2 Replies

3. Shell Programming and Scripting

How to ignore single or multiple lines between /* and */ while reading from a file in unix?

I have a file proc.txt: if @debug = 1 then message 'Start Processing ', @procname, dateformat(now(*), 'hh:mm:ss'), @julian type info to client; end if; /* execute immediate with quotes 'insert into sys_suppdata (property, value, key_name) location ''' || @supp_server || '.' ||... (5 Replies)
Discussion started by: kidncute
5 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

5. UNIX for Advanced & Expert Users

Unix Command to rename a file in a zipped folder

Hi, I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..??? Thanks in advance.. (1 Reply)
Discussion started by: Victoria.Sam
1 Replies

6. Shell Programming and Scripting

rename multiple filename.45267.txt to >> filename.txt

i have several thousand files and in subdirs that are named file.46634.txt budget.75346.pdf etc i want to remove the number but retain the extension. it is always a 5 digit. thanks. (6 Replies)
Discussion started by: jason7
6 Replies

7. Shell Programming and Scripting

mv command to rename multiple files that retain some portion of the original file nam

Well the title is not too good, so I will explain. I need to move (rename) files using a simple AIX script. ???file1.txt ???file2.txt ???file1a.txt ???file2a.txt to be: ???renamedfile1'date'.txt ???renamedfile2'date'.txt ???renamedfile1a'date'.txt ???renamedfile2a'date'.txt ... (4 Replies)
Discussion started by: grimace15
4 Replies

8. Shell Programming and Scripting

how to rename multiple files with a single command

Hi I have following list of files at a path: 01.AR.asset 01.AR.index 01.AR.asset.vf 01.AR.asset.xv I want to rename all these files as follows: 73.AR.asset.Z 73.AR.index.Z 73.AR.asset.vf.Z 73.AR.asset.xv.Z Can any body give me a single command to acheive the above results. ... (5 Replies)
Discussion started by: tayyabq8
5 Replies

9. UNIX for Dummies Questions & Answers

Change multiple filename formats with WHILE

Hi All, I'm trying to run a simple shell program to change all the files named *.cvs to *.txt. I am trying to use WHILE and this is what I have so far: This changes the first file from *.cvs to *.txt, but it is not cycling through the other files. My suspicion is that I don't have the... (5 Replies)
Discussion started by: ScKaSx
5 Replies

10. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies

Featured Tech Videos