sed script problem

May 27, 2009 at 22:41:30
Specs: AIX
My file content is like this :

PIN (P1) {
a1 : p9;
a2: q9
a3: t9
}

PIN ( P2) {
aw: oo;
aq:op;
ac:ry;
}

PIN (P5) {
am : jk;
al: lo;
as : ll;
}

PIN (4) {
as : ii;
ad: l;
sw:ll:
}

I want to remove the First three Blocks
So that my resultant file should be

PIN (4) {
as : ii;
ad: l;
sw:ll:
}

I am using
This sed
sed '/PIN1/,/PIN5/d' file

But it is not matching the end of the Block with PIN Group PIN5

and printing this content

am : jk;
al: lo;
as : ll;
}

PIN (4) {
as : ii;
ad: l;
sw:ll:
}

How to match the PIN5 and the end of the Block }

Thanks

Neha


See More: sed script problem

Report •


#1
May 28, 2009 at 01:14:42
sed is not appropriate here. use awk
# awk 'BEGIN{RS=""}NR==4' file
PIN (4) {
as : ii;
ad: l;
sw:ll:
}



Report •

#2
May 28, 2009 at 01:31:51
Somehow This is not fullfilling the requirement which I need
Actually the file is very big and the subset of my file is

PIN (P1) {
a1 : p9;
a2: q9
a3: t9
}

PIN ( P2) {
aw: oo;
aq:op;
ac:ry;
}

PIN (P5) {
am : jk;
al: lo;
as : ll;
}

PIN (4) {
as : ii;
ad: l;
sw:ll:
}

The script should match pattern P1 and P5 and it should remove all the Blocks related to that but the rest of the file content it should not touch


Report •

#3
May 28, 2009 at 02:10:38
then use NR>4

Report •

Related Solutions

#4
May 28, 2009 at 02:37:48
awk '/P1/,/P5/{c=4};--c<0' file > newfile

Hi ! This script is working fine


Report •


Ask Question