Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageThomas 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
Post Follow-up to this messagesorry 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
Post Follow-up to this message
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.
Post Follow-up to this messageThomas 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 !~ /^\+/
Post Follow-up to this messagethanks 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.
Post Follow-up to this messagethanks 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.