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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting try to batch rename using sed (if this is best)
# 1  
Old 02-09-2011
Java 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 '/.dat.old/_N.dat'

this only works in the terminal and just gives a print out of the changed names
I'd like it to actually rename the files in batch from with a script that i'd call rename.sh that i can run.

thanks
# 2  
Old 02-09-2011
Taking what you already have:

Code:
$ ls *.dat.old | sed 'p;s/.dat.old/_N.dat/' | xargs -n2 mv

This User Gave Thanks to Scott For This Post:
# 3  
Old 02-09-2011
Code:
for file in *.dat.old
do
  mv "$file" "${file%.dat.old}_N.dat"
done

This User Gave Thanks to cfajohnson For This Post:
# 4  
Old 02-09-2011
great thanks much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed batch file issue

Hi!! I want to create a batch file so the sh file could change a file on a specific time. I made this config: sed -i 's/range 192.168.1.200 192.168.1.220;/option POLYCOM "tftp://10.20.1.10";/g' /etc/dhcp3/dhcpd.conf My issue is that the sed does not accept the :// character.... (2 Replies)
Discussion started by: jocas9
2 Replies

2. UNIX for Dummies Questions & Answers

Script batch with command sed

hi, i have a folder with 2000 text file where each file contain a string. i need to trasform this string like this: example of file : My name is Mark and I'm a child the new file must be: insert into tabella ('My name','My name is Mark and I'm a child'); where the first column is a... (11 Replies)
Discussion started by: yo-yo78
11 Replies

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

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

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

use sed do batch wildcard string replace

Hi, Here is what I want to do I want to search local directory and its sub directory, all the files which contain any string like _12345, then remove this string. String is a combination of _ plus a random integer number. For example, here is one line in a file before <properties... (1 Reply)
Discussion started by: bp5000
1 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. UNIX for Dummies Questions & Answers

batch file using sed command in msdos

<! pad_meth: <! program = "/usr/lib/drivers/pse/x29d -p" how should i program it in oder to display this: <! pad_meth: <! program = "/usr/lib/drivers/pse/x29d -p" ;) (1 Reply)
Discussion started by: rita1985
1 Replies

9. UNIX for Advanced & Expert Users

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 ... (7 Replies)
Discussion started by: reldb
7 Replies

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