Search code examples
linuxsedawktcsh

How to delete all lines between the pattern lines


I have text with either the following structure

bla bla more bla bla
$ 
PART  /  4402000LLINK    4401001
NAME ADHESIVE   8.0 mm LLINK Property                                           


        8.                  8.         2
END_PART
$
some other bla bla

But the line containing PART could be also:

PART  /  4402000   LLINK 4401001

or:

PART  /  4402000  LLINK  4401001

So strictly speaking the LLINK could occupy the columns from 16 to 23. Now I would like to delete all lines between the pattern lines. First pattern is line containing both PART and this LLINK. The second pattern is line containing END_PART. So at the end I will have this:

bla bla more bla bla 
$
$
some other bla bla

I am using CentOS with:

> echo $SHELL
/bin/tcsh

so, I can use sed or awk in tcsh e.g. Could you help. Thank you


Solution

  • This sed command can be used.

    sed -i -r '/PART.*LLINK/,/END_PART/d' file