Computing.Net > Forums > Programming > sed script problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

sed script problem

Reply to Message Icon

Name: neha_008
Date: May 27, 2009 at 22:41:30 Pacific
OS: AIX
Subcategory: Opinions
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: May 28, 2009 at 01:14:42 Pacific
Reply:

sed is not appropriate here. use awk

# awk 'BEGIN{RS=""}NR==4' file
PIN (4) {
as : ii;
ad: l;
sw:ll:
}



0

Response Number 2
Name: neha_008
Date: May 28, 2009 at 01:31:51 Pacific
Reply:

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


0

Response Number 3
Name: ghostdog
Date: May 28, 2009 at 02:10:38 Pacific
Reply:

then use NR>4


0

Response Number 4
Name: neha_008
Date: May 28, 2009 at 02:37:48 Pacific
Reply:

awk '/P1/,/P5/{c=4};--c<0' file > newfile

Hi ! This script is working fine


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: sed script problem

login script problem www.computing.net/answers/programming/login-script-problem/8742.html

Perl Script Problem www.computing.net/answers/programming/perl-script-problem/7932.html

Windows Scripting problem www.computing.net/answers/programming/windows-scripting-problem/13641.html