Home > Archive > AWK > October 2004 > removing text block
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
removing text block
|
|
| Thomas Toth 2004-10-05, 3:55 pm |
| 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
| |
| Ed Morton 2004-10-05, 3:55 pm |
|
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
| |
| William James 2004-10-05, 3:55 pm |
| /\.SUBCKT CCT1/, /\.ENDS/ { next }
9
| |
| Thomas Toth 2004-10-06, 8:55 am |
| 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
| |
| Ed Morton 2004-10-07, 3:55 am |
|
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.
| |
| William James 2004-10-07, 3:55 am |
| 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 !~ /^\+/
| |
| Thomas Toth 2004-10-07, 8:55 am |
| 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.
| |
| Thomas Toth 2004-10-13, 8:55 pm |
| 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.
|
|
|
|
|