bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blank lines -- not a bug


From: Stepan Kasal
Subject: Re: Blank lines -- not a bug
Date: Mon, 24 Jun 2002 06:51:21 +0000 (UTC)
User-agent: slrn/0.9.6.2 (Linux)

> On Sun, 23 Jun 2002 09:05:28 +0000, Kaye Odedina <address@hidden> wrote:
> > While trying to perform this task "Exchange the line containing Paco with 
> > the line containing Vinh" , I came across this error.
> > 
> > The solution should be "sed -e '/Vinh/h' -e '/Paco/x' datebook"

Hallo again,
        the right solution might be to run sed several times, cocatenating
the output:

( sed -e '/Paco/,${;/Vinh/!d;}' datebook
  sed -e '/Paco/,/Vinh/!d;/Vinh/d;/Paco/d' datebook
  sed -e '1,/Vinh/{;/Paco/!d;}' datebook
) > outputfile

or even:

( sed -ne '/Paco/q;p' datebook
  grep Vinh datebook
  sed -ne '/Vinh/q;1,/Paco/!p' datebook
  grep Paco datebook
  sed -e '1,/Vinh/d' datebook
) > outputfile

Another alternative is to use awk.  For example the following program:

BEGIN { save = 0 }
/Paco|Vinh/ {
        if (save == 0) {
                paco_line = $0
                save = 1
                remember = ""
        } else {
                printf "%s", $0
                print remember
                print paco_line
                save = 0
        }
        next
}
save == 1 {
        remember = remember "\n" $0
        next
}
{ print }

Hope this helps,
        Stepan Kasal





reply via email to

[Prev in Thread] Current Thread [Next in Thread]