You are not logged in.

#1 2005-05-25 19:49:35

nordlicht
Member
From: Hamburg/Germany
Registered: 2003-07-23
Posts: 62

How To replace chars in filenames?

Hi

what have I to do to use rename in a shell script?

I want to replace all ' (single quote) in a directory tree with another char. I need this because xargs wont work with such filenames.

The ' are in different positions and in different long filenames, so I cant use the ? spacer.

What else can I do?

thank you


Chris

Offline

#2 2005-05-25 20:35:53

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: How To replace chars in filenames?

Escape the ''s, like "mv ' bla".

Offline

#3 2005-05-25 21:19:09

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: How To replace chars in filenames?

I think he's looking for something like:
mv abdc'ewff'efe something

in a "do this for all files" version...
nordlicht: do you want to keep the current filenames? i.e. hello'this'is'a'file becomes hellothisisafile?

for f in `ls *'*`; do
  mv $f `echo $f | sed  -e "s/'/_/g"`
done

that should replace single quotes with underscores...

Offline

#4 2005-05-25 21:58:53

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: How To replace chars in filenames?

Use tr "'" "_" or sed "y/'/_/".

Offline

#5 2005-05-25 22:08:45

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: How To replace chars in filenames?

i3839 wrote:

Use tr "'" "_" or sed "y/'/_/".

Yeah, yeah - there's more than one way to beat a horse... errr whatever that saying is

Offline

#6 2005-05-25 22:15:24

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: How To replace chars in filenames?

Ah sorry, I missed the 'g' at the end of the sed command, that works too yes.

Offline

Board footer

Powered by FluxBB