Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion exec sed with special arguments

View parsed - Show only message text

Path: g2news1.google.com!postnews.google.com!l42g2000hsc.googlegroups.com!not-for-mail
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Newsgroups: comp.lang.tcl
Subject: Re: exec sed with special arguments
Date: Mon, 22 Sep 2008 09:06:17 -0700 (PDT)
Organization: http://groups.google.com
Lines: 61
Message-ID: <aba26877-6d2e-4bdd-9c27-a867004739ca@l42g2000hsc.googlegroups.com>
References: <13cf0d5c-994f-4261-855f-9d2bf9947b91@c65g2000hsa.googlegroups.com>
NNTP-Posting-Host: 193.49.124.107
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1222099577 29685 127.0.0.1 (22 Sep 2008 16:06:17 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 22 Sep 2008 16:06:17 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: l42g2000hsc.googlegroups.com; posting-host=193.49.124.107; 
	posting-account=6MdBDQoAAADRhV18594oFolEODD2QSrg
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) 
	Gecko/2008072914 CentOS/3.0.1-3.el4.centos Firefox/3.0.1,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 fulmar (NetCache NetApp/6.0.7), 1.1 goodway (NetCache 
	NetApp/6.1.1), 1.1 goodway (NetCache NetApp/6.1.1), 1.1 goodway (NetCache 
	NetApp/6.1.1)

On Sep 22, 5:25=A0pm, trighole <fabrice.bernardgran...@gmail.com> wrote:
> Hello,
>
> I try to use sed command with special arguments and it fails.
> 1- In deed I want to add 'TITI' before a '{' and add 'TOTO' after the
> '{' so I write
> exec sed -e '/{/aTITI' -e '/{/iTOTO' inFile > outFile
> TCL error is: missing close-brace: possible unbalanced brace in
> comment.

Beware single quote is not a metacharacter in Tcl. You want:

  exec sed -e "/\{/aTITI" -e "/\{/iTOTO"

> To solve it I use \ to 'protect' the curly brace
> exec sed -e '\/{/aTITI' -e '/\{/iTOTO' inFile > outFile
> and TCL error is sed: -e expression #1, char 1: Unknown command: `''

First I think the first expression started with '/\{' and not '\/
{' (otherwise you'd have received the same punition as before).
Second, this shows you that the single quotes are passed to the
underlying program (sed) as normal characters, as explained above.
Of course usually you type all this in one of the sh or csh families,
where single quotes play a different role ;-)

> 2- I also want to replace
> //BLABLA by //BLOBLO
> exec sed -e "s//BLABLA///BLOBLO" =A0inFile > outFile
> TCL error: sed: -e expression #1, char 0: No previous regular
> expression

After visiting sh's and (a bit of) Tcl's Quoting Hells, welcome to
sed's :-)
Though you can escape slashes this way:

    exec sed -e "s/\\/\\/BLABLA/\\/\\/BLOBLO/"

or (only Tcl-quoting differs):

    exec sed -e {s/\/\/BLABLA/\/\/BLOBLO/}

sed has a much nicer tool: you can use any character instead of "/" as
the s-command arg separator. So choose one that doesn't collide with
your own regexp and you're saved:

    exec sed -e s@//BLABLA@//BLOBLO@

-Alex




> To solve it I use \ to 'protect' /
> I still got the same error.
>
> Can U help me
>
> thanks
>
> fab


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google