Found a workarround :
command :
------------------------------
sed -e "s/\"//g" "test.txt>test2.txt"
------------------------------
Works as intended.
Sry for disturbing.
2009/11/13 Guillaume Frambourg <frambourg...@gmail.com>
> Hi,
>
> When you try to replace " with some character that is not escaped, it
> works. But it won't accept to save the output in another file.
>
> ie :
>
> test.txt contains
>
> "hello"
>
> Working sed is :
> --------------------------------------------------------
> sed -e "s/\"//g" test.txt
> --------------------------------------------------------
>
> it outputs :
> --------------------------------------------------------
> hello
> --------------------------------------------------------
>
> But if you try :
> --------------------------------------------------------
> sed -e "s/\"//g" test.txt > test2.txt
> --------------------------------------------------------
>
> it outputs :
> --------------------------------------------------------
> hello
> sed: can't read >: Invalid argument
> --------------------------------------------------------
>
> Also trying :
> --------------------------------------------------------
> sed -e "s/\"/\"test/g" test.txt > test2.txt
> --------------------------------------------------------
>
> it outputs "testhello"test into test2.txt
>
>
> So using an escaped character in search string but not in replacestring
> breaks the command line interpretation.
>
> Thanks
>
That's not a problem with Sed, this is a problem with the Windows
shell's too naive handling of quotes. The Windows shell doesn't
understand the backslash escape, so it thinks the second quote closes
the first one, and the 3rd one quotes everything up to the end of the
command.
The escape character of the Windows shell is `^'. However, it doesn't
escape inside quoted strings :-(. So you need to get creative. For
example:
sed -e "s/"^""//g" test.txt > test2.txt
This quotes parts of the Sed expression separately, with the literal
quote escaped by `^'.
The DJGPP port of set works OK, because it parse the command line
itself. But both the Cygwin and the MinGW ports emit the given error
message.
>
> The escape character of the Windows shell is `^'. However, it doesn't
> escape inside quoted strings :-(. So you need to get creative. For
> example:
>
> sed -e "s/"^""//g" test.txt > test2.txt
>
> This quotes parts of the Sed expression separately, with the literal
> quote escaped by `^'.
This does not work for me. It seems that quotes in the command line must
always be in pairs. I.e. there must be an even number of quotes in each
argument. The workaround is to use the octal escape code for the quote
character:
sed -e "s/\042//g" test.txt > test2.txt
Hope this helps.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado