rename the file in batch


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users rename the file in batch
# 1  
Old 12-11-2006
rename the file in batch

In my dir there are files like

a.xml
b.xml
abnc.xml
12.abc.xml
12.anc.sfoioi.xml

I need to remove .xml from all the files

Is there any direct way without using any for/do loop

Right now i am using
for file in *
do
newfile=${file%.xml}
mv file $newfile
done

Please let me know if there is any direct way in one line without any loop
# 2  
Old 12-11-2006
for f in *.xml ; do mv $f ${f%.xml} ; done

gets it in one line...still a loop though.
# 3  
Old 12-12-2006
ls -1| awk -F ".xml" '{print "mv ", $1".xml",$1}' | ksh

Check if it works.
# 4  
Old 12-12-2006
thanks

hey kapilraj
that was really kool man ...

thanks a lot ...
# 5  
Old 12-12-2006
That has a bug though it does'nt hurt.

A neat one would be

ls -1 *.xml | awk -F ".xml" '{print "mv ", $1".xml",$1}'
# 6  
Old 09-28-2007
bash-2.03$ ls -1
TEST.xml.123
TEST2.ABC.xml
TEST2.ABC.xml.123
bash-2.03$

bash-2.03$ ls -1| awk -F".123" '{print $1}'
TEST
TEST2
TEST2
bash-


How can i get output as
TEST.xml
TEST2.ABC
TEST2.ABC.xml

even though i gave -F as .123 but it always take as . (not considering 123 after dot)
# 7  
Old 09-28-2007
never mind, i use nawk instead of awk and it worked fine (i am using SUN OS)
oh HP awk worked fine
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Batch Script To Unzip and Rename File

Hello All, I need help in writing a batch script. I have 100 zip files in a folder. Each zip file has a unique name starting with XYZ_12345.zip Each zip file contains single csv file I would like to batch extract the files and also rename the extracted csv as per the original zip name... (6 Replies)
Discussion started by: rajlakshmi
6 Replies

2. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

3. Shell Programming and Scripting

Batch rename files that do not match pattern

Hi all, I do not have programming experience and mostly use one-liner or sometimes more to get the job done. I am having problem to batch rename the files that do not match a particular pattern. Sample file-names from directory: Meeting_Packages.pdf 13_textfile0 19_textfile0 ... (3 Replies)
Discussion started by: atulkakrana
3 Replies

4. Shell Programming and Scripting

try to batch rename using sed (if this is best)

hi gooday I need some help with a rename I am attempting. I'd like to rename a bunch of files in a folder example list.dat.old to list_N.dat query.dat.old to query_N.dat note the two periods in (.dat.old) to become _N.dat I tried using sed like this ls *.dat.old | sed... (3 Replies)
Discussion started by: johnstrong
3 Replies

5. Shell Programming and Scripting

Batch rename files after internal search pattern

Hello all I am trying to do a script that would allow me to mass rename files after a grep search within them. They are XML files and the pattern I would like to append to the file name is easy to find (e.g. <filename>foo</filename>), but I can't for the life of me find out how to do it and... (2 Replies)
Discussion started by: aavv
2 Replies

6. Shell Programming and Scripting

Batch file to remove double quotes from a file

Hi I have to create a windows batch file which will read an input file and remove "double quotes" from each line of the file. For eg.If input file name is abcd.csv and contents is : "asasd,123123,213213,asd" "esfrf,dsfsdf,234324,sdfsdf" Then the batch file should remove "" from the... (11 Replies)
Discussion started by: akashtcs
11 Replies

7. UNIX for Dummies Questions & Answers

Batch rename recursively

I would like to replace multiple underscores with hyphens but I have 26,000 files to rename. They are all in one file structure and multiple sub-directories. It would be much simpler if I had a script to do it. Here are some samples of the file names: Example 1... (3 Replies)
Discussion started by: ..Chris..
3 Replies

8. Programming

batch file

what is a command to call a batch file from a c++ program when called with the argument which is a text file, then how to print that text file on a printer. please help me with code if possible (3 Replies)
Discussion started by: ramneek
3 Replies

9. Shell Programming and Scripting

rename in batch

example test1 will have m1234567.12a I would like to rename in batch but I don't Please help me on this. cd /a1/a2/a3 test1=$(basename /a1/a2/a3/*.*) >> /tmp/t echo $test1 echo "Extracting 8 th position" >> /tmp/t2 awk '{print substr($1,8,1); }' $test1 >> /tmp/t3 echo "extraction ... (3 Replies)
Discussion started by: kathy18
3 Replies
Login or Register to Ask a Question