I'm using GNU sed version 4.0.7 on Win XP.
I'm having problems with double quotes when using sed on win xp. The
command and the output is as follows:
---
D:\>d:\GnuWin32\bin\sed.exe -n "s;.*=\"\(.*\.doc\).*;\1;p" file.txt >
temp.txt
thisandthat.doc
d:\GnuWin32\bin\sed.exe: can't read >: Invalid argument
---
The content of file.txt is as follows:
-------
<a class="pr" href="thisandthat.doc"><u>
-------
The file "temp.txt" does not get created. However, it works okay if I
remove the double quotes from the script, i.e. the following works
fine:
sed.exe -n "s;.*=\(.*\.doc\).*;\1;p" file.txt > temp.txt
but that's not what I want.
Since sed won't accept single quotes on windows, how can I include the
double quotes in the script on the cmdline and redirect the output to
a file?
Any clues?
Regards
Kek
> I'm having problems with double quotes when using sed on win xp. The
> command and the output is as follows:
If using gnu sed then replace double quotes within the command with \x22
(the hex value of the ascii character)
chk wrote:
>
> I'm using GNU sed version 4.0.7 on Win XP.
>
> I'm having problems with double quotes when using sed on win xp. The
> command and the output is as follows:
> ---
> D:\>d:\GnuWin32\bin\sed.exe -n "s;.*=\"\(.*\.doc\).*;\1;p" file.txt >
> temp.txt
> thisandthat.doc
> d:\GnuWin32\bin\sed.exe: can't read >: Invalid argument
> ---
the escape character in cmd.exe is the caret (not the backslash) and it
only works outside of quoted material. So you should change your command
to
d:\GnuWin32\bin\sed.exe -n "s;.*="^""\(.*\.doc\).*;\1;p" file.txt > temp.txt
Note the "^"" near the start of the pattern. The first quote ends the
quoted material, than ^" inserts a quote into the pattern, and the third
quote starts the quoting of the remaining pattern and substitution text.
Regards,
Jürgen
--
Jürgen Krämer Softwareentwicklung
Habel GmbH mailto:j...@habel.de
Hinteres Öschle 2 Tel: (0 74 61) 93 53 - 15
78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 - 99
Try closing and opening the quotes before and after the literal quote:
sed -n "s;.*="\""\(.*\.doc\).*;\1;p" file.txt > temp.txt
Both versions work properly under Win9x command.
If you're running under XP cmd shell, and XP still has command shell
available, you might want to try using that instead.
If that doesn't work, try using a Unix-like shell that allows single
quotes, like bash.
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian....@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
Jurgen's suggestion below, works.
d:\GnuWin32\bin\sed.exe -n "s;.*="^""\(.*\.doc\).*;\1;p" file.txt >
temp.txt
So does foxidrive's (using \x22).
However, Brian Inglis's suggestion didn't work (Thanks anyway :)). I
needed the "caret" character as Jurgen suggested.
Cheers
-Kek
Jürgen Krämer <j...@habel.de> wrote in message news:<41357252$0$19557$9b4e...@newsread2.arcor-online.net>...