Re: simple question
Artem B. Bityuckiy wrote:
>if there are always 4 lines, you can do
> I have a number of files with BSD-license header:
> * Copyright (c) 2000
> * Konstantin Chuguev. All rights reserved.
> * Redistribution and use in source and binary forms, with or without
> * modification, are permitted provided that the following conditions
> * are met:
> * 1. Redistributions of source code must retain the above copyright
> * notice, this list of conditions and the following disclaimer.
> * 2. Redistributions in binary form must reproduce the above copyright
> * notice, this list of conditions and the following disclaimer in the
> * documentation and/or other materials provided with the distribution.
> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> ANY WAY
> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> * SUCH DAMAGE.
> * iconv (Charset Conversion Library) v2.0
> I want to remove the 3 advertising clause (with permission of authors)
> from it, i.e the following lines:
> * 3. All advertising materials mentioning features or use of this software
> * must display the following acknowledgement:
> * This product includes software developed by Konstantin Chuguev
> * and its contributors.
:g/3\. All advertising materials/,+3d
Jürgen Krämer Softwareentwicklung
Habel GmbH mailto:jkr@...
Hinteres Öschle 2 Tel: (0 74 61) 93 53 15
78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 99
> 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.Looks like a job for argdo and an ex command. Something like this
> What's next?
one-liner (if OE breaks the line, just make sure it's keyed in as one
:argdo 1/All advertising materials mentioning/-3,/All advertising
should do the trick if it's truely the three lines *above* that you want
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
+1 the line after the search result
+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