Click to See Complete Forum and Search --> : escaping . character in sed


pickarooney
09-06-2004, 05:04 PM
I'm trying to write a little script for replacing one character with another in a filename. Very straightforward unless the replaced or replacing character is a full-stop/period.

If I only wanted to replace or replace with this character I could simply escape it with a backslash, but this is not the case.

I also want to have the option of not replacing characters in the extension, so for example with a script called replace_char which takes two arguments, the replaced and replacing character,

replace_char a.file.called.foo.txt . _

would give a_file_called_foo.txt and not a_file_called_foo_txt
I've done this before using basename, or so I thought, but the manual only explains how to do it with a known file extension, e.g. basename a_file_called_foo.txt .txt

Any hints would be greatly appreciated.

P