LinuxQuestions.org
Review your favorite Linux distribution.
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 09-27-2007, 12:12 PM   #1
clem_c_rock
LQ Newbie
 
Registered: Jul 2004
Posts: 5

Rep: Reputation: 0
Cannot replace spaces w/ underscores


Hello,
I'm desperately trying to replace some files w/ spaces in the names w/ underscores.

I ran this command in a directory: rename " " _ *\ * and it worked like a charm on every file except this one:

MissMarieBand_Oh_No!_Not Again.wmv

I then tried to take to remove the spaces w/ this: rename "s/ *//g" *.mov

and it still ignores this file.

Is there any way I can get around this?

Thanks,
Clem
 
Old 09-27-2007, 12:30 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
The *.mov in the command you specified:
Code:
rename "s/ *//g" *.mov
Means the command will only apply to files which end in ".mov", so it should not work on one ending in ".wmv", like the one you named.
 
Old 09-27-2007, 12:32 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
I think the problem is the "!" in the filename - it shouldn't be there.
 
Old 09-27-2007, 12:33 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
rename " " _ *\ *
I don't see what the syntax of this is.


This:
Quote:
rename "s/ *//g" *.mov
operates on all files ending in ".mov", but yours ends in ".wmv" Also, it only replaces 2 or more occurences of " ". Try 's/ //g'
 
Old 09-27-2007, 12:41 PM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
For example:
Code:
tg@vaio:~$ touch "MissMarieBand_Oh_No!_Not Again.wmv"
bash: !_Not: event not found
tg@vaio:~$ touch "MissMarieBand_Oh_No\!_Not Again.wmv"
tg@vaio:~$ ls Miss*
MissMarieBand_Oh_No\!_Not Again.wmv
So get rid of the "!"
Edit: Like this:
Code:
tg@vaio:~$ mv MissMarieBand_Oh_No\!_Not\ Again.wmv   MissMarieBand_Oh_No_Not_Again.wmv
/Edit

Last edited by tredegar; 09-27-2007 at 12:55 PM.
 
Old 09-27-2007, 12:54 PM   #6
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
Try this, it worked on my pc:
mv MissMarieBand_Oh_No\!\ Again.wmv MissMarieBand_Oh_No\!_Again.wmw

I hope it is a good song.
 
Old 09-27-2007, 12:56 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I oopsed---"*" means ZERO or more instances of the previous expression. Here is the para from "man regex"

A piece is an atom possibly followed by a single(!) `*', `+', `?', or
bound. An atom followed by `*' matches a sequence of 0 or more matches
of the atom. An atom followed by `+' matches a sequence of 1 or more
matches of the atom. An atom followed by `?' matches a sequence of 0
or 1 matches of the atom.

And, yes, ANY special character in a filename is bad news....
 
Old 09-27-2007, 02:17 PM   #8
clem_c_rock
LQ Newbie
 
Registered: Jul 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Great - thanks for all the feedback. I am a command line tard for sure.

This did the trick for me:

mv MissMarieBand_Oh_No\!_Not\ Again.wmv MissMarieBand_Oh_No_Not_Again.wmv
 
  


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
need to replace spaces with comma (ascii file) ferradura Linux - Software 3 02-02-2007 09:39 PM
Bug: Some characters temporarily appear as underscores triffix Linux - Desktop 0 11-05-2006 05:07 PM
Aterm Underscores CrEsPo Linux - Software 3 09-15-2006 02:23 PM
How do i change spaces inside a txt file, and replace space with backslash \? repolona Linux - Newbie 1 05-24-2006 06:08 AM
How to replace spaces in filenames with underscores rosslaird Linux - Software 4 02-22-2005 02:08 AM

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

All times are GMT -5. The time now is 11:35 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration