Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

removing text block
hi again,

i need to remove a block of text between clearly identifyable patterns.
anything that is between .SUBCKT CCT1 and the next .ENDS needs to be
removed.

question: is it feasible in awk or is it better to use perl (or
something else)? if so, could you give me a hint?

i would like to use awk but i have the feeling that it might not be very
suitable for this one.

thanks a lot,

tom

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Toth
10-05-04 08:55 PM


Re: removing text block

Thomas Toth wrote:

> hi again,
>
> i need to remove a block of text between clearly identifyable patterns.
> anything that is between .SUBCKT CCT1 and the next .ENDS needs to be
> removed.
>
> question: is it feasible in awk

Yes.

or is it better to use perl (or
> something else)? if so, could you give me a hint?
>
> i would like to use awk but i have the feeling that it might not be very
> suitable for this one.

Awk can do it, but you need to tell us if those patterns appear on their
own lines or can be in the middle of other text. Some sample input and
output would help.

Ed.

> thanks a lot,
>
> tom

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
10-05-04 08:55 PM


Re: removing text block
/\.SUBCKT CCT1/, /\.ENDS/ { next }
9

Report this thread to moderator Post Follow-up to this message
Old Post
William James
10-05-04 08:55 PM


Re: removing text block
sorry for having forgotten about that. the .SUBCKT and .ENDS are always
at the beginning of a line, but the number of pins is arbitrary.

input:

.SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
...
...
...
.ENDS

desired output:

.SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
.ENDS

thinking of it, things could be complicated by the fact that if the
line(s) immediately following .SUBCKT start with a + then they should
not be removed. other lines starting with + need to go.

sample output:

.SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
+ pin6 pin7 pin8
.ENDS

thanks a lot,

tom


Ed Morton wrote:

Thomas Toth wrote:

> hi again,
>
> i need to remove a block of text between clearly identifyable patterns.
> anything that is between .SUBCKT CCT1 and the next .ENDS needs to be
> removed.
>
> question: is it feasible in awk

Yes.

or is it better to use perl (or
> something else)? if so, could you give me a hint?
>
> i would like to use awk but i have the feeling that it might not be very
> suitable for this one.

Awk can do it, but you need to tell us if those patterns appear on their
own lines or can be in the middle of other text. Some sample input and
output would help.

Ed.

> thanks a lot,
>
> tom

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Toth
10-06-04 01:55 PM


Re: removing text block

Thomas Toth wrote:

> sorry for having forgotten about that. the .SUBCKT and .ENDS are always
> at the beginning of a line, but the number of pins is arbitrary.
>
> input:
>
> .SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
> ...
> ...
> ...
> .ENDS
>
> desired output:
>
> .SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
> .ENDS
>
> thinking of it, things could be complicated by the fact that if the
> line(s) immediately following .SUBCKT start with a + then they should
> not be removed. other lines starting with + need to go.
>
> sample output:
>
> .SUBCKT CCT1 pin1 pin2 pin3 pin4 pin5
> + pin6 pin7 pin8
> .ENDS


This should do it (untested):

gawk 'state == "gotStart" || state == "gotPlus" {
if ($1 == "+") {
state = "gotPlus"
} else {
state = "gotText"
}
}
$1 == ".SUBCKT" && $2 == "CCT1" { state = "gotStart" }
$1 == ".ENDS" { state = "gotEnd" }
state == "gotText" { next }
{ print }'

and please don't top-post.

Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
10-07-04 08:55 AM


Re: removing text block
Thomas Toth <user@example.net> wrote in message news:<4163d76f$0$28012
> thinking of it, things could be complicated by the fact that if the
> line(s) immediately following .SUBCKT start with a + then they should
> not be removed. other lines starting with + need to go.

BEGIN { pat1="^\.SUBCKT CCT1"; pat2 ="^\.ENDS"; pat=pat1 "|" pat2 }

##  Handle block between pat1 and pat2.  Print only lines starting
##  with with pat1, pat2, or "+".
$0 ~ pat1, $0 ~ pat2 { if ($0 ~ pat || $0 ~ /^\+/) print; next }

##  Print line unless starting with "+".
$0 !~ /^\+/

Report this thread to moderator Post Follow-up to this message
Old Post
William James
10-07-04 08:55 AM


Re: removing text block
thanks everyone for the help, the solutions worked.

and sorry for top-posting, my mozilla was having an issue with the news
server.

tom

Ed Morton wrote:
>
>
> Thomas Toth wrote:
> 
>
>
>
> This should do it (untested):
>
> gawk 'state == "gotStart" || state == "gotPlus" {
>                 if ($1 == "+") {
>                         state = "gotPlus"
>                 } else {
>                         state = "gotText"
>                 }
>         }
>         $1 == ".SUBCKT" && $2 == "CCT1" { state = "gotStart" }
>         $1 == ".ENDS" { state = "gotEnd" }
>         state == "gotText" { next }
>         { print }'
>
> and please don't top-post.
>
>     Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Toth
10-07-04 01:55 PM


Re: removing text block
thanks everyone for the help, the solutions worked.

and sorry for top-posting, my mozilla was having an issue with the news
server.

tom

Ed Morton wrote:
>
>
> Thomas Toth wrote:
> 
>
>
>
> This should do it (untested):
>
> gawk 'state == "gotStart" || state == "gotPlus" {
>                 if ($1 == "+") {
>                         state = "gotPlus"
>                 } else {
>                         state = "gotText"
>                 }
>         }
>         $1 == ".SUBCKT" && $2 == "CCT1" { state = "gotStart" }
>         $1 == ".ENDS" { state = "gotEnd" }
>         state == "gotText" { next }
>         { print }'
>
> and please don't top-post.
>
>     Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Toth
10-14-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.