Rename files extensions

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename files extensions
# 1  
Old 08-16-2009
Rename files extensions

Hello !

i have a few files like ...

// to

and i would like to rename those files to ...

// to

how can i do that ???

thanks in advance !! Smilie
# 2  
Old 08-16-2009
hope this will guide you..
echo "setup.001"|sed 's/.0/.r/g'

# 3  
Old 08-16-2009
wow thanks a lot !! it worked almost flawlessly !

i did ...

for file in setup.* ; do mv $file `echo $file | sed 's/.0/.r/g'` ; done

everything went right except i lost every "ten"

i got

//but somehow i lost setup.r10

//but somehow i lost setup.r20

etc ...

i would need some regex to apply to tens

if i make

echo "setup.010"|sed 's/.0/.r/g'

i got ..


unfortunately i don't know much about regex Smilie

Last edited by Putazo; 08-16-2009 at 04:19 AM..
# 4  
Old 08-16-2009
Simple, use the rename command as
rename s/\.[0-9]/.r/ *

# 5  
Old 08-16-2009
i don't have the rename command in my shell Smilie
# 6  
Old 08-16-2009
Originally Posted by Putazo
sed 's/.0/.r/g'

sed 's/.0/.r/'

# 7  
Old 08-16-2009
# or bash

# split filename using dot to the two variable
ls setup.* | while IFS="." read start end 

        # substring starting from second char and give length nothing = rest of data
        [ "$newname" = "$oldname" ] && continue
        # remove echo if looks good
        echo mv "$oldname" "$newname"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mv all files with different extensions to a new name

Hello all! I want to move several files foo.aux foo.log foo.pdf foo.tex to bar_foo.aux bar_foo.pdf bar_foo.tex I am on tcsh % mv foo.* bar_!#:1 is not working. Thank you for your help marek (11 Replies)
Discussion started by: marek
11 Replies

2. Shell Programming and Scripting

Copy files with different extensions and same name

Hi, i have two folders. Folder A has 1000+ files with just images named like : 01012015.png 01022015.png etc. Folder B has much more files, part of them with same name as png files folder others not. Instead of folder A wich are only images, these are audio wav files. I need to... (11 Replies)
Discussion started by: Board27
11 Replies

3. Shell Programming and Scripting

looping through files with different extensions

Hi all, I am trying to make a for loop invoking files with different extensions (*.ugrd and *.vgrd) and I cant just make it work. Cant figure out how to load the files so as to use them in subsequent commands like the ones in this pseudo code. the files are arranged such that in one date for... (8 Replies)
Discussion started by: ida1215
8 Replies

4. Shell Programming and Scripting

rename file, add extensions

Hi Guys, I have files named myfileaa,myfileab,myfileac,myfilesad.... till myfileav. Now i needs to rename all these files to myfileaa.txt ,myfileab.txt,myfileac.txt. Please help me how to do the same. Thanks in advance..!!! (4 Replies)
Discussion started by: jaituteja
4 Replies

5. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

6. Shell Programming and Scripting

Give extensions to files which do not have an extension

HI, I have a bunch of files on my Linux system which do not have a file name extension in them. I want to process them with "sed" (using loop) but can't do so. Is there any way to give an extension to files which have no extension in them in Linux? Currently files are like this: cat dog... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. Shell Programming and Scripting

Sorting Files according to their Extensions...

I am trying to write a Korne Shell Script wherein we have to sort files according to their extensions(for eg.,, together; 4.csh, 120.csh, 6.csh together and 7.ksh, 2.ksh, 59.ksh together) and move them to their respective directories viz. sh, csh and ksh... I think,... (1 Reply)
Discussion started by: marconi
1 Replies

8. Shell Programming and Scripting

Find files with 3 different extensions

Hi all, From one directory I need to fetch only files of type *.xls,*.csv,*.txt. I tried the find . -name '*.txt,*.csv,*.xls' -print. But it throws me error. Please do help me on this. Thanks Mahalakshmi.A (11 Replies)
Discussion started by: mahalakshmi
11 Replies

9. UNIX for Dummies Questions & Answers

List Files by Extensions

I have a unix directory with 500 plus files . When I do a ls -lR I can see ALL the files here . How can I sort this by the files extensions ? I can't enter ls -lR *.ext1 *.ext2 *.ext3 etc in case I miss out some files . (2 Replies)
Discussion started by: newbienix
2 Replies

10. UNIX for Dummies Questions & Answers

Command to select files with different extensions

I want to select files which have different extensions such as .cpp, .cs, .h I can select one of them as find . -name "*.cpp" but I want to select all of them in one command only. It should be pretty simple but I'm not able to get it. Any help with the command will be greatly appreciated. (1 Reply)
Discussion started by: MobileUser
1 Replies
Login or Register to Ask a Question