Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion exec sed with special arguments
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexandre Ferrieux  
View profile  
 More options Sep 22 2008, 12:06 pm
Newsgroups: comp.lang.tcl
From: Alexandre Ferrieux <alexandre.ferri...@gmail.com>
Date: Mon, 22 Sep 2008 09:06:17 -0700 (PDT)
Local: Mon, Sep 22 2008 12:06 pm
Subject: Re: exec sed with special arguments
On Sep 22, 5:25 pm, 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"  inFile > 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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

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