Renaming files with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming files with sed
# 1  
Old 03-20-2011
Renaming files with sed

Hi all,

I created file like this

AAb.lol
AAc.lol
AAx.lol
test.sh

My goal is to create a script (test.sh) which renames all the files to their original name without AA. I want to end up with this:
b.lol
c.lol
x.lol

Using sed how is it possible?

i tried to write the script

Code:
#!/bin/bash
for i in $( ls ); do
    NewName='sed' 's/AA//g' '$i'
    mv '$i' $NewName
done

The output however is a lot of times this:

Quote:
./test.sh: line 3: s/AA//g: No such file or directory
mv: missing destination file operand after `$i'
From that 2nd line i can tell that $NewName is just empty. I also read something about sed needing the -e option for scripting purposes but i just don't understand it

With Regards
Anish Kumar.V

Last edited by anishkumarv; 03-20-2011 at 01:46 PM.. Reason: reason
# 2  
Old 03-20-2011
Code:
for file in AA*; do
  mv "$file" "${file#AA}"
done

This User Gave Thanks to Scott For This Post:
# 3  
Old 03-20-2011
Hi scottn,

Code:
#!/bin/bash
for i in *.lol
do
        mv $i $(echo $i | sed "s/AA//")

done

finally i got this code also works..!! thanks a lot...dude

With Regards
Anish Kumar.V

Last edited by anishkumarv; 03-20-2011 at 02:00 PM.. Reason: forget to put code tag
# 4  
Old 03-20-2011
Code:
rename AA "" *.lol

will do the job.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming files

Hi i have to achieve the following i have files as xyz001.csv, xyz002.csv.......xyz0025.csv in a folder, i need to keep xyz001.csv as it is but want to remove the extra zero on filename from 10 say xyz0010 should be renamed to xyz010 xyz0025 should be renamed as xyz025 Note xyz... (8 Replies)
Discussion started by: mad_man12
8 Replies

3. Shell Programming and Scripting

Renaming CERTAIN files

Hello I have a folder with around a 100 files. Some of these files have an extension of .DAT.csv and the others are simply .DAT I need to rename all those files ending in .DAT.csv to .DAT. I tried out the following script: cd /data/AED/DEV/IN/MENSUEL/B3C/FEERIE/BASCULE/TEST cnt=1 for fname... (3 Replies)
Discussion started by: S. BASU
3 Replies

4. Shell Programming and Scripting

Help with renaming file using sed

Hi, I am currently updating a script, It should do the ff: rename the YYYYMMDD in mainlog.YYYYMMDD to $NEW_DATE I was ask to use sed but I am not that familiar with it. I should update the touch part with the sed. Please kindly help me with this. Thanks a lot. ... (3 Replies)
Discussion started by: joyful1213
3 Replies

5. UNIX for Dummies Questions & Answers

renaming multiple files using sed or awk one liner

hi, I have a directory "test" under which there are 3 files a.txt,b.txt and c.txt. I need to rename those files to a.pl,b.pl and c.pl respectively. is it possible to achieve this in a sed or awk one liner? i have searched but many of them are scripts. I need to do this in a one liner. I... (2 Replies)
Discussion started by: pandeesh
2 Replies

6. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

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

8. Shell Programming and Scripting

Question about SED cutting and renaming

Hi. I've posted a couple of questions on my little project before, and it's been helpful, but things just keep changing on my end. Allow me to explain. I'm getting hundreds of .txt files, each containing the results of a database search from a newspaper. EAch file contains the news stories... (10 Replies)
Discussion started by: spindoctor
10 Replies

9. UNIX for Dummies Questions & Answers

Help with renaming files

Anyone out there know how, in a one line UNIX Command, I could rename(mv) a file that contains variable string as part of its name. The variable string is the process instance number. For example, I'd like to be able to rename XX_XXXXX_nnnnn.pdf (where nnnnn is a number and its value depends on... (4 Replies)
Discussion started by: mc_cool_e
4 Replies
Login or Register to Ask a Question