LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2007, 01:07 AM   #1
seimour
LQ Newbie
 
Registered: Feb 2006
Location: Euroland
Distribution: Debian Stable
Posts: 26

Rep: Reputation: 15
Question how to rename files using sed?


Hello!

First of all I'd like to mention that your forums are a pain in the ass to walk through using links. Sorry if being rude but I got to tell it... Lots of links... getting mad to just post this :/ .

Well, talking about my doubt.. I've a little problem with a bunch of files I need to rename. They come from my almost extinc windows partition, and their names have a lot of spaces (), //, a mix of capital letters and the like.

I know there are some fancy guis that can do this but I'd like to do it using commands. I've got some practice with sed but it only can rename the strings it gets from ls, for example (just replacing blank spaces with '.'):

ls -R | sed 's/ /./g'

would output (no capital letters touched yet):

001.Paris.Eiffel.Tower.jpg

So, how can I make mv or rename accept those formatted lines as an input? Is it possible to do it without an script?


Thanks in advance. Regards.

<edit>got to use firefox in the end to correct some typos</edit>

Last edited by seimour; 05-02-2007 at 01:15 AM.
 
Old 05-02-2007, 01:46 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
One way is
Code:
mv foo $(echo foo | sed 's/foo/bar/')
See 'Command Substitution' in the bash manual. Also check out the 'rename' command.

If you want to use ls output, you'll need a for loop.
Code:
for f in $(ls); do mv $f $(echo $f | sed 's/a/z/'); done
though that's ugly and slow.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rename files linux2man Linux - General 8 02-03-2007 05:26 AM
how to rename muliple files manishsingh4u Linux - General 6 05-21-2006 07:59 AM
rename files allelopath Linux - General 5 07-05-2005 03:00 AM
Files Rename on boot kofrad Slackware 2 05-07-2004 04:50 AM
Can not rename files. Maximus2000 Linux - General 0 04-22-2004 01:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration