sed script question
John Macdonald
john-Z7w/En0MP3xWk0Htik3J/w at public.gmane.org
Tue Jan 18 05:21:17 UTC 2005
On Monday 17 January 2005 23:50, jim ruxton wrote:
> I'm trying to write a script and in it one of the things I want to do is
> get rid of [ characters. When I try using sed as in:
> sed s/"["/" "/g
> I get an error message saying it is an unterminated s command. I have a
> feeling this is because [ is a special character. I thought however
> putting quotes around it would take care of this. Any thoughts on what
> I'm doing wrong? Thanks.
> Jim
The way you wrote the command, the quotes were treated as special
by the shell. So, when sed actually saw its argument, it was s/[/ /g.
As you thought, [ is a special character. It begins a character class,
which includes everything up until the matching ] as characters, any
one of which can be matched at that point - since you had no ] you
got the complaint. To make [ be a normal character, you backwhack
it. So, what you want to have sed see is: s/\[/ /g
However, the [, blank, and backslash are also magical to the shell so
you need to use appropriate protection there too, by quoting (as you
originally thought). So: sed 's/\[/ /g' is what you want.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list