Reputation: 101
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
Upvotes: 0
Views: 96
Reputation: 21903
With awk, this seems to work :
$ cat file
bla PART bla more bla bla
$
PART / 4402000LLINK 4401001
NAME ADHESIVE 8.0 mm LLINK Property
PART
8. 8. 2
END_PART
$
some other bla bla
AAAAA
PART / 4402120 LLINK 4401001
NAME ADHESIVE 8.0 mm LLINK Property
PART
AAAAAAAAAA
8. 8. 2
END_PART
$AAAA
AAAAAsome other bla bla
awk '{if (($0!~/PART/ || $0!~/LLINK/) && stop == 0) {print} else {if ($0~/END_PART/) {stop=0} else {stop=1}}}' file
bla PART bla more bla bla
$
$
some other bla bla
AAAAA
$AAAA
AAAAAsome other bla bla
Hope this helps !
Upvotes: 0
Reputation: 3375
This sed
command can be used.
sed -i -r '/PART.*LLINK/,/END_PART/d' file
Upvotes: 3