ed /pattern/ command

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default ed /pattern/ command

    I want to edit a file in several places that contain a certain pattern.

    file:

    title
    a
    b
    c
    title
    a
    b
    c
    title
    a
    b
    c

    My command file:

    #!/bin/sh
    ed grub.conf <<EOF
    /title/
    a
    password --md5 \$1\$Bg2gu/\$Zv3cGRU19XWCrU.963Cs71
    ..
    w
    q
    EOF


    How can I add the line after every occurence of "title" ?

    Please cc me.

    --
    Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    Christoph Kukulies Guest

  2. Similar Questions and Discussions

    1. Invalid color: colored pattern specified withuncolored pattern colorspace.
      Hi. Just installed Mac OS X 10.4 Tiger and note the following message flooding the system.log when using Acrobat Pro version 7.0.1. Apr 30...
    2. Acrobat 6.01: File Command disappears on Command Bar
      On the Command Bar (File, Edit, View, etc.) the File Command disappears in many Acrobat operations. Is there a parameter available to insure that...
    3. RUN/execute a Command-Line command from an ASP page.
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    4. Windows Explorer Right Click Command (+ Custom Command Script)
      Ok got a tricky question about custom scripts, I would like to add a Windows Explorer Right Click Command - that allows me to select an image/s...
    5. Multi command files and running them from the command prompt
      Use the -td§ option . Details are in the section titled Command Line Processor Options in the Command Reference. "Derek Clarkson"...
  3. #2

    Default Re: ed /pattern/ command

    Fletcher Glenn <fandmgiiNOSPAM@pacbell.net> wrote:
    > "Christoph Kukulies" <kuku@accms33.physik.rwth-aachen.de> wrote in message
    > news:bee0re$5de$1@nets3.rz.RWTH-Aachen.DE...
    >> I want to edit a file in several places that contain a certain pattern.
    >>
    >> file:
    >>
    >> title
    >> a
    >> b
    >> c
    >> title
    >> a
    >> b
    >> c
    >> title
    >> a
    >> b
    >> c
    >>
    >> My command file:
    >>
    >> #!/bin/sh
    >> ed grub.conf <<EOF
    >> /title/
    >> a
    >> password --md5 \$1\$Bg2gu/\$Zv3cGRU19XWCrU.963Cs71
    >> .
    >> w
    >> q
    >> EOF
    >>
    >>
    >> How can I add the line after every occurence of "title" ?
    >>
    >> Please cc me.
    >>
    >> --
    >> Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    >>
    > Instead of the two lines:
    > /title/
    > a
    > Try the following:
    > g/title/s/$/^M password --etc/
    probably I'd have to escape the $ from the shell.
    > The "g" command says "on every line containing the pattern".
    > The "s" command says "substitute the second pattern for the first".
    > $ is the end of the line.
    Sure, that is all known but I tried to prepend the /title/ with a g(lobal)
    and it didn't work. Why does it not work with the a(ppend) command?

    Or is it that your solution is a one line command and mine is
    spread over several lines? Could I pack the a(ppend) stuff in
    a oneliner also?
    > ^M is produced by entering "control-V" followed by "return(or enter)".
    Or typing ^V^M (control-V, control-M) (keyboard travel optimized :-)

    Yes, I know that (^V escape)
    > You might also have to add another ^M to the end of the pattern.
    Thanks.


    --
    Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    Christoph Kukulies Guest

  4. #3

    Default Re: ed /pattern/ command

    Christoph Kukulies wrote:
    >
    > Fletcher Glenn <fandmgiiNOSPAM@pacbell.net> wrote:
    >
    > > "Christoph Kukulies" <kuku@accms33.physik.rwth-aachen.de> wrote in message
    > > news:bee0re$5de$1@nets3.rz.RWTH-Aachen.DE...
    > >> I want to edit a file in several places that contain a certain pattern.
    > >>
    > >> file:
    > >>
    > >> title
    > >> a
    > >> b
    > >> c
    > >> title
    > >> a
    > >> b
    > >> c
    > >> title
    > >> a
    > >> b
    > >> c
    > >>
    > >> My command file:
    > >>
    > >> #!/bin/sh
    > >> ed grub.conf <<EOF
    > >> /title/
    > >> a
    > >> password --md5 \$1\$Bg2gu/\$Zv3cGRU19XWCrU.963Cs71
    > >> .
    > >> w
    > >> q
    > >> EOF
    > >>
    > >>
    > >> How can I add the line after every occurence of "title" ?
    > >>
    > >> Please cc me.
    > >>
    > >> --
    > >> Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    > >>
    >
    > > Instead of the two lines:
    >
    > > /title/
    > > a
    >
    > > Try the following:
    >
    > > g/title/s/$/^M password --etc/
    >
    > probably I'd have to escape the $ from the shell.
    >
    > > The "g" command says "on every line containing the pattern".
    > > The "s" command says "substitute the second pattern for the first".
    > > $ is the end of the line.
    >
    > Sure, that is all known but I tried to prepend the /title/ with a g(lobal)
    > and it didn't work. Why does it not work with the a(ppend) command?
    >
    > Or is it that your solution is a one line command and mine is
    > spread over several lines? Could I pack the a(ppend) stuff in
    > a oneliner also?
    >
    > > ^M is produced by entering "control-V" followed by "return(or enter)".
    >
    > Or typing ^V^M (control-V, control-M) (keyboard travel optimized :-)
    >
    > Yes, I know that (^V escape)
    >
    > > You might also have to add another ^M to the end of the pattern.
    >
    > Thanks.
    >
    > --
    > Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    The 'g' command is only in effect for that one line. Any commands
    that follow the 'g' command are not affected by it.

    --
    Fletcher Glenn
    email [email]f-g-l-e-n-n@quest.com[/email] (remove the dashes)
    Fletcher Glenn Guest

  5. #4

    Default Re: ed /pattern/ command

    Fletcher Glenn <fandmgiiNOSPAM@pacbell.net> wrote:
    > g/title/s/$/^M password --etc/
    > The "g" command says "on every line containing the pattern".
    > The "s" command says "substitute the second pattern for the first".
    > $ is the end of the line.
    > ^M is produced by entering "control-V" followed by "return(or enter)".
    > You might also have to add another ^M to the end of the pattern.
    > YMMV,
    Indeed, my mileage varies. I'm getting ^M literally inserted rather
    than a line feed.

    --
    Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    Christoph Kukulies Guest

  6. #5

    Default Re: ed /pattern/ command

    Fletcher Glenn <fandmgiiNOSPAM@pacbell.net> wrote:
    > g/title/s/$/^M password --etc/
    Yeuch.

    g/title/a\
    password --whatever\
    ..

    -- [mdw]
    Mark Wooding Guest

  7. #6

    Default Re: ed /pattern/ command

    Mark Wooding <mdw@nsict.org> wrote:
    > Fletcher Glenn <fandmgiiNOSPAM@pacbell.net> wrote:
    >> g/title/s/$/^M password --etc/
    > Yeuch.
    > g/title/a\
    > password --whatever\
    > .
    Hhmm. Doesn't work. Gives the typical

    48
    ?

    --
    Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
    Christoph Kukulies Guest

  8. #7

    Default Re: ed /pattern/ command

    Christoph Kukulies <kuku@accms33.physik.rwth-aachen.de> wrote:
    > Hhmm. Doesn't work. Gives the typical
    >
    > 48
    > ?
    How strange. I tested it on Linux and Solaris, so I doubt I've done
    anything particularly weird. You remembered the backslash-newlines?

    -- [mdw]
    Mark Wooding Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139