Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sed win xp double quotes and redirection

44 views
Skip to first unread message

chk

unread,
Aug 31, 2004, 11:42:46 PM8/31/04
to
Hi all

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

foxidrive

unread,
Sep 1, 2004, 2:10:36 AM9/1/04
to
On 31 Aug 2004 20:42:46 -0700, chk wrote:

> 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)

Jürgen Krämer

unread,
Sep 1, 2004, 2:54:42 AM9/1/04
to

Hi,

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

Brian Inglis

unread,
Sep 1, 2004, 1:44:13 PM9/1/04
to
On 31 Aug 2004 20:42:46 -0700 in comp.editors, tms...@yahoo.com (chk)
wrote:

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

chk

unread,
Sep 2, 2004, 3:30:53 AM9/2/04
to
Thanks muchly to all who responded.

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>...

0 new messages