sed '/foo/a bar' does not work in a script

sed '/foo/a bar' does not work in a script

Post by Eduardo Chappa L » Mon, 08 May 2000 04:00:00



Hello

  I am having problems with my version of sed. I can make the command

sed '/foo/a bar' file

work from the command line, but not from a script. The error is that the
letter "b" of bar is considered as an extra character after the command
"a". Does anyone know what's going on here? I can solve this problem in
another longer way, but I would like to have a solution of this
form. Anyone has any idea?

  Thanks.

--
Eduardo
http://www.math.washington.edu/~chappa/pine/

 
 
 

sed '/foo/a bar' does not work in a script

Post by Michael Sternber » Mon, 08 May 2000 04:00:00



> sed '/foo/a bar' file
> work from the command line, but not from a script.

A leading regex in sed constitutes a line address.  sed expects a command to run on matching lines.  In above case, the command is invalid syntax.  Based on popular use of sed, I believe you forgot two things: 's' and '/'

  sed 's/foo/a bar/' file

Regards,
--
Michael Sternberg                        | Uni-GH Paderborn
http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
phone: +49-(0)5251-60-2329   fax: -3435  | 33098 Paderborn, Germany
"Who disturrrbs me at this time?"  << Zaphod Beeblebrox IV >>     <*>

 
 
 

sed '/foo/a bar' does not work in a script

Post by Craig Peterei » Mon, 08 May 2000 04:00:00




> > sed '/foo/a bar' file work from the command line, but not from a script.

> A leading regex in sed constitutes a line address.  sed expects a command to
> run on matching lines.  In above case, the command is invalid syntax.  Based
> on popular use of sed, I believe you forgot two things: 's' and '/'

>   sed 's/foo/a bar/' file

I think he's trying to use the a (append) command to append "bar" after lines
containing "foo".

Try putting this in your script:

sed '/foo/a\
bar'

--
Craig Peterein

 
 
 

sed '/foo/a bar' does not work in a script

Post by Chris Costell » Mon, 08 May 2000 04:00:00



> I think he's trying to use the a (append) command to append "bar" after lines
> containing "foo".
> Try putting this in your script:
> sed '/foo/a\
> bar'

  That will work, and so will:  sed -e '/foo/a\' -e 'bar' file


 
 
 

sed '/foo/a bar' does not work in a script

Post by Al A » Tue, 09 May 2000 04:00:00



: > I think he's trying to use the a (append) command to append "bar" after lines
: > containing "foo".

: > Try putting this in your script:

: > sed '/foo/a\
: > bar'

:   That will work, and so will:  sed -e '/foo/a\' -e 'bar' file

                                                beautiful

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

 
 
 

sed '/foo/a bar' does not work in a script

Post by Michael Sternber » Tue, 09 May 2000 04:00:00





> : > I think he's trying to use the a (append) command to append "bar" [..]
> : > containing "foo".

Well, we don't know yet ;-)

Quote:> : > Try putting this in your script:>
> : > sed '/foo/a\
> : > bar'
> :   That will work, and so will:  sed -e '/foo/a\' -e 'bar' file
>                                                 beautiful

Beautiful it is, alas:

        % sed -e '/foo/a\' -e 'bar'
    OSF1, HP-UX:
        sed: Found escape character at end of editing script.
    Solaris:
        Undefined label: ar
    GNU, BSD:
        (fine)

A multi-line script IS painful in csh (not that I'd endorse it).

Regards,
--
Michael Sternberg                        | Uni-GH Paderborn
http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
phone: +49-(0)5251-60-2329   fax: -3435  | 33098 Paderborn, Germany
"Who disturrrbs me at this time?"  << Zaphod Beeblebrox IV >>     <*>

 
 
 

sed '/foo/a bar' does not work in a script

Post by Ron DuFresn » Wed, 10 May 2000 04:00:00


IRIX 5.3 reports like solaris:

Undefined label: ar

Laterer,

Ron DuFresne



:> : > I think he's trying to use the a (append) command to append "bar" [..]
:> : > containing "foo".

: Well, we don't know yet ;-)

:> : > Try putting this in your script:>
:> : > sed '/foo/a\
:> : > bar'
:> :   That will work, and so will:  sed -e '/foo/a\' -e 'bar' file
:>                                                 beautiful

: Beautiful it is, alas:

:       % sed -e '/foo/a\' -e 'bar'
:     OSF1, HP-UX:
:       sed: Found escape character at end of editing script.
:     Solaris:
:       Undefined label: ar
:     GNU, BSD:
:       (fine)

: A multi-line script IS painful in csh (not that I'd endorse it).

: Regards,
: --
: Michael Sternberg                        | Uni-GH Paderborn
: http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
: phone: +49-(0)5251-60-2329   fax: -3435  | 33098 Paderborn, Germany
: "Who disturrrbs me at this time?"  << Zaphod Beeblebrox IV >>   <*>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Cutting the space budget really restores my faith in humanity.  It
eliminates dreams, goals, and ideals and lets us get straight to the
business of hate, debauchery, and self-annihilation." -- Johnny Hart
        ***testing, only testing, and damn good at it too!***

OK, so you're a Ph.D.  Just don't touch anything.

 
 
 

1. Q: grep 'foo' NOT followed by 'bar'

Hello,

I want to use some grep command to match lines that contain
some word and NOT followed by another.
Examples:
    [1]    ^foo$
    [2]    ^foobar$
    [3]    ^foo foobar$
    [4]    ^fooba$

I want to grep on 'foo' NOT followed by 'bar'. So line 1, 3 and
4 would match. (line 3 has a foo NOT followed by bar)

Question:
    How should I do this?
    I tried a few things but did not succeed. (I rtfm, the Unix FAQ
    and O'Reilly's Unix in a Nutshell I believe)
    This may not matter but I try to do this on AIX 3.2.5

Cheers,
Vincent Zocca

PS: I noteced that our nn is freaked up (21 hours no news and I am
    no longer sysadmin) so an email would help me quicker I believe.

2. update_vm_cache

3. Installing Doom...svgalib, brio ken pipe! Help.

4. PROBLEM: 'sed' script 's/^ /\n/' not working properly

5. TZ problem after running for 30+ days

6. http://foo/bar != http://foo/bar/index.html

7. (5/7) cleanup apicid <-> cpu mapping

8. Need Help: 'tar xvMf /dev/fd0 foo' not working properly

9. 'gcc foo.c -g -lX11' don't work?!?

10. sed -e 's/\nFOO\n/\\chapter{FOO}/g'

11. 'echo "some text" |read foo' results in empty $foo

12. sed -e '/^t\{2,\}/d' foo