LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to change several filename (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-change-several-filename-172424/)

jan_81 04-20-2004 05:44 AM

Script to change several filename
 
I need to change many filename that have similar name.
Example:

I have about 100 file named "hello world" and I want change all them name in "hi world".
I've tried some command like "find" and "mv" but I didn't manage to make it...

Thanks.. by the way Hi all!!

Jan

TroelsSmit 04-20-2004 07:11 AM

Put an if sentence and a concatenation into the following script:

#!/usr/bin/tcsh
#filer i et directory
foreach fil (`find /home/you/path -type f`)
mv $fil $newfilname
end

jan_81 04-20-2004 07:45 AM

Perhaps I didn't explain very well.. sorry for my bad english..

I have several similar files...

00001-hello-world-00001
00002-hello-world-00002
00003-hello-world-00003
...
...

I want to change for all these files the word "hello" with the word "hi" so that I'll have the files named

00001-hi-world-00001
00002-hi-world-00002
...

jan_81 04-22-2004 08:06 AM

up

Muzzy 04-24-2004 02:22 AM

This seems to work, although its not clear form your description if all the files are in the ssame directory or in different directories. If they are in different directories then this won't work without some modification.

for f in *; do mv "$f" "`echo $f | sed s/hello-world/hi-world/`"; done

Be careful with all the " and ` s!!

There is probably a better way of doing this, and I would like to see other people's improved suggestions, but this should do for your purposes.

Mark.

jan_81 04-28-2004 11:10 AM

I don't mind the better way, it's important that it works.. :)
Anyway, for the moment I can't try your script. I've just resolved the problem in another way... manually one by one!! Surely I'll try your script the next time and I'll make you to know as it goes... :)

Thanks

Bye at all


All times are GMT -5. The time now is 11:08 AM.