Loading ...
Sorry, an error occurred while loading the content.

Re: simple question

Expand Messages
  • Tim Chase
    ... *` ... Looks like a job for argdo and an ex command. Something like this one-liner (if OE breaks the line, just make sure it s keyed in as one line) ...
    Message 1 of 23 , Dec 3, 2003
    • 0 Attachment
      > The right way is to do the following:
      > 1. find "All advertising materials mentioning" pattern
      > 2. delete this line and 3 lines above.
      >
      > But how to do this?
      >
      > I've opened all such files by
      >
      > > vim `grep -l -r "Redistribution and use in source and binary forms"
      *`
      > command.
      >
      > What's next?

      Looks like a job for argdo and an ex command. Something like this
      one-liner (if OE breaks the line, just make sure it's keyed in as one
      line)

      :argdo 1/All advertising materials mentioning/-3,/All advertising
      materials mentioning/-1d

      should do the trick if it's truely the three lines *above* that you want
      to delete.

      Jurgen's answer was close, however, if you have any *other* lines
      (improbable as it may be) that match that regex, it will hose them too.
      It also deletes the three lines *following* the "All advertising..." line.
      If it's the three lines *after* that you want, but you only want to do it
      for the first instance, this will pull it off:

      :argdo 1/All advertising materials/+1,+2d

      The first one breaks down as

      :argdo for each file in the argument list
      1 go to the first line
      /All ..ning/ search for the text
      -3 beginning three lines before it
      , and ending at
      /All ..ning/ where you find the next bit of text from that starting point
      -1 the line before the one you just found
      d delete 'em

      The second one breaks down a little more cleanly, the same as the above
      only
      +1 the line after the search result
      , through
      +2 two lines after the line we just found
      d delete it

      You'll want to make sure you have 'hidden' set so you can approve all the
      changes, and then you can either :w them each as you confirm the
      correctness, or just :wall them to write them all.

      If you have faith, you can skip having 'hidden' set, and just append a
      pipe followed by a "w" to write each file after the changes have been made

      :argdo 1/All advertising materials/+1,+2d|w

      HTH,

      -tim
    Your message has been successfully submitted and would be delivered to recipients shortly.