sed -e 's/\'a\'/\';\'/' ?

sed -e 's/\'a\'/\';\'/' ?

Post by Nele Paulse » Tue, 19 Jan 1999 04:00:00



Hi,

my question is, how can I mask the single
quotation mark in my file for sed

I have a lot of SQL-Loader files of this kind:

cat t55.ctl
load data
infile 't55'
truncate
into table A_220_T55
fields terminated by ';' TRAILING NULLCOLS
(AAA_000_KEY    char ,
B_220_BBB_LFD_NR char ,
AAA_220_BBB     char )

there is given a delimiter ';'

The delimiter should be changed to a.

#!/bin/ksh
#set -x
for file in t*.ctl
do
sed -e 's/;/a/' $file >$file.new
mv $file.new $file
done

That's ok.

Now the delimiter should be rechanged from a to ;.
I'd tried

sed -e 's/\'a\'/\';\'/' $file >$file.new

It doesn't work.

How to mask the single quotation mark inside the sed command?

TIA,

Nele

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by Dragan Jurkovi » Tue, 19 Jan 1999 04:00:00


sed -e "s/'a'/';'/" $file > $file.new      (works under 2.6)

Dragan Jurkovic
MRRM (Canada) Inc.

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by Bernard P. Murray, P » Tue, 19 Jan 1999 04:00:00



> Hi,

> my question is, how can I mask the single
> quotation mark in my file for sed
[snip]
> TIA,
> Nele

I doubt if this is Solaris-specific, but...

I'm not sure I gathered what you were after but
if it is a simple swap from ; to . then maybe
tr would be better than sed?  Alternatively,
use the octal codes for the problem characters?
     The comp.lang.awk newsgroup may be a better
bet for this question.
     Good luck,
          Bernard
--
Bernard P. Murray, PhD
Dept. Cell. Mol. Pharmacol., UCSF, San Francisco, USA

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by Neil Ricke » Tue, 19 Jan 1999 04:00:00



>my question is, how can I mask the single
>quotation mark in my file for sed

You should be able to use either:

 sed -e "s/'a'/';'/"

or

 sed -e s/\'a\'/\';\'/

But it won't work the way you tried it.

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by Al A » Wed, 20 Jan 1999 04:00:00


        will NOT answer your q per se
        but
        i once posted to seders:
                commandline sed scripts considered harmful

        i.e.
        when u have conflict with the shell
        bypass the shell

        how

        use a sedscript file, instead

         -------------------------------------------------
        to master                       regular expressions
        to master                       sed            
        join my informal email list     seders          

         -------------------------------------------------

: Hi,

: my question is, how can I mask the single
: quotation mark in my file for sed

: I have a lot of SQL-Loader files of this kind:

: cat t55.ctl
: load data
: infile 't55'
: truncate
: into table A_220_T55
: fields terminated by ';' TRAILING NULLCOLS
: (AAA_000_KEY    char ,
: B_220_BBB_LFD_NR char ,
: AAA_220_BBB     char )

: there is given a delimiter ';'

: The delimiter should be changed to a.

: #!/bin/ksh
: #set -x
: for file in t*.ctl
: do
: sed -e 's/;/a/' $file >$file.new
: mv $file.new $file
: done

: That's ok.

: Now the delimiter should be rechanged from a to ;.
: I'd tried

: sed -e 's/\'a\'/\';\'/' $file >$file.new

: It doesn't work.

: How to mask the single quotation mark inside the sed command?

: TIA,

: Nele

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by Ken Pizzi » Wed, 20 Jan 1999 04:00:00




Quote:>sed -e 's/\'a\'/\';\'/' $file >$file.new

>It doesn't work.

>How to mask the single quotation mark inside the sed command?

This is not a sed-specific problem --- it is an issue of how to
get the command-interpreter of one's choice to pass command-line
arguments of one's choice to a program.  Two fairly generic ways
of doing this with Bourne-class shells (like ksh, which was indicated
in an omitted section of the original post) are:
  1. use double-quotes to protect the arguments containing
     single-quotes from shell interpretation:
        sed "s/'a'/';'/" "$file" >"$file.new"
  2. bounce in-and-out of single-quote mode (since there is
     no mechanism in Bourne-class shells for escaping a
     single-quote within single-quotes):
        sed 's/'\''a'\''/'\'';'\''/' "$file" >"$file.new"

(Stratagy #2 is quite visually ugly, and unnecessary for this
particular problem.  But there exist some other contexts in
which it is extremly useful to know this method --- specifically
when you have a rare need for a single quote in a long argument
which contains many $s and/or `s which you do not wish expanded.)

                --Ken Pizzini

 
 
 

sed -e 's/\'a\'/\';\'/' ?

Post by hans maye » Mon, 25 Jan 1999 04:00:00




>>my question is, how can I mask the single
>>quotation mark in my file for sed

>You should be able to use either:

> sed -e "s/'a'/';'/"

>or

> sed -e s/\'a\'/\';\'/

>But it won't work the way you tried it.

no this doesn't work. why making a quotation mark ?
the following works perfect on my solaris 2.5.1 with ksh , sh and csh

root> echo 'a;' | sed -e "s/a/;/"        
;;
root> echo 'a;' | sed -e "s/;/a/"
aa

--
best regards from vienna           |   mayer (at) unisys.co.at_SPAM
hans                               |   mayer (at) relay.bfl.at_SPAM

 
 
 

1. sed and '/' to '\/' conversion.

I would love for someone to explain the following problem I am having with
sed.  I am using the Bourne Shell under HP-UX 9.01.

The task : To use sed to manipulate a variable from having /'s in the string
           to having \/'s in the string.

Example  : Converting a/b/c to a\/b\/c

Notes    : I am far from a sed guru, but I can usually get it to do what I
           want (as long as it's simple enough).

Okay, this is what I go about doing.

First I try to do it on the command line :
    % echo "a/b/c" | sed -e "s/\//\\\\\//g"

Then I put it into a script.

    #!/bin/sh
    VAR="a/b/c"
    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\//g"`

and try to run it.

    sed: command garbled: s/\//\\//g

but if I try :

    #!/bin/sh

    convert ()
    {
        echo "$1" | sed -e "s/\//\\\\\//g"
    }

    VAR="a/b/c"
    NEWVAR=`convert $VAR`
    echo "NEWVAR is : $NEWVAR"

and try to run it.

    NEWVAR is : a\/b\/c

Okay, I don't get it!  What is the difference?  Why does one work and the
other not work?

Well, not one to let sleeping dogs lie, I keep pounding away at it and put
together the following :

    #!/bin/sh

    VAR="a/b/c"

    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\\\\//g"`
    echo "NEWVAR is : $NEWVAR"

    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\\\\\//g"`
    echo "NEWVAR is : $NEWVAR"

    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\\\\\\//g"`
    echo "NEWVAR is : $NEWVAR"

    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\\\\\\\//g"`
    echo "NEWVAR is : $NEWVAR"

    NEWVAR=`echo "$VAR" | sed -e "s/\//\\\\\\\\\\\\\//g"`
    echo "NEWVAR is : $NEWVAR"

which when run results in :

    sed: command garbled: s/\//\\//g
    NEWVAR is :
    NEWVAR is : a\/b\/c
    NEWVAR is : a\/b\/c
    NEWVAR is : a\/b\/c
    sed: command garbled: s/\//\\\\//g
    NEWVAR is :

Okay, now I'm really confused, why do the THREE in the middle work?

Any explanations much appreciated.

/Jim

--
 ------------------------------------------------------------------------------


  Atmospheric Environment Service

2. Ensoniq Soundscape driver broken in 2.0.3x ?

3. Does sed '/'$var'/d' textfile work if $var has / in it???

4. Simple Method for HTTP GET Request

5. alpha sort: 'sed'/'awk'?

6. how to change shell

7. Can 'require' override 'allow'/'deny' (Apache)

8. File execution problem

9. Why does 'ls' give '/' as the output?

10. replacing '/' with '\\'

11. Why does 'ls' give '/' as the output?

12. How to do 'tunefs' on '/'

13. 'mail'/'sendmail' with higher priority??