Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'What about filenames with spaces?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
What about filenames with spaces?
Authored by: Chas on May 11, '01 10:44:37PM

This trick sounds good, but it doesn't work with files with spaces in the names. On Unix, I'm used to manipulating files with names like "really_long_filename.txt" but on the Mac they tend to be things like "really long filename.txt" and they don't parse the same way, you need extra help in deglobbing. I haven't quite figured this out, any hints or tricks you could suggest? I just had to manually rename 40 files because of this problem.



[ Reply to This | # ]
What about filenames with spaces?
Authored by: elfkinz on May 20, '02 12:31:54PM

Try adding sed 's/ / /g' after the ls and before the awk:

ls foo*.jpg | sed 's/ / /g' | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2'

This should take care of the spaces ... the only problem I can't figure out yet is removing spaces from the file names.



[ Reply to This | # ]
What about filenames with spaces?
Authored by: xurizaemon on Jul 17, '08 03:35:36PM

The perl script "rename" above handles them fine.

I love stringing various tools together, but that little perl snippet does what I mostly need (piping the filenames thru sed) without me having to think twice about quoting.



[ Reply to This | # ]
Hypertalk versus unix..
Authored by: RagnarokOfBorg on Jan 19, '11 08:25:12PM

AAARGGH! (Now I understand how my mother feels about the Finder - how I feel about perl and unix..) I try that and it complains about an invalid command code ? (sed: 1: "s/Voyager/VOY/2": invalid command code ?). The perl script complains that it can't understand $expr.. I'll just fire up Revolution a bit later and write it in damn (nouveau) HyperTalk.. At least it has a command " replace "foo" with "bar" in tStr ".. Now I'll have to see if it has a command 'rename file <>' Oh, I'll just use the " shell() " function - which I found after about a second with google.. Apple really dropped the ball when they killed Hypercard - and then the apocryphal QuickTime 3..



[ Reply to This | # ]