selectively add the end of the line

selectively add the end of the line

am 17.04.2008 16:59:38 von RickM

Im sure this one is very easy but I can get want Im after. I have a
spice file that looks like this:

..subckt CKNXLVTD3 A ZN
M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
..ends

and it needs to look like this:

..subckt CKNXLVTD3 A ZN VSS VDD
M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
..ends

Basically, search for .subckt and append VSS and VDD to the line
only. The line length can be long or short

Thanks

Re: selectively add the end of the line

am 17.04.2008 17:17:50 von RickM

Yep, the both work!!!! Can you give a brief description how this
works. I was only able to print the subckt line.
What does the trailing "1" do on the awk solution?

THANKS!!!!!!

Rick


On Apr 17, 8:29 am, Dave B wrote:
> On Thursday 17 April 2008 16:59, ri...@galaxy.nsc.com wrote:
>
>
>
> > Im sure this one is very easy but I can get want Im after. I have a
> > spice file that looks like this:
>
> > .subckt CKNXLVTD3 A ZN
> > M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> > M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> > D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> > .ends
>
> > and it needs to look like this:
>
> > .subckt CKNXLVTD3 A ZN VSS VDD
> > M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> > M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> > D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> > .ends
>
> > Basically, search for .subckt and append VSS and VDD to the line
> > only. The line length can be long or short
>
> Uhm...
>
> sed 's/^\.subckt.*/& VSS VDD/' yourfile
>
> or
>
> awk '/^\.subckt/ {$0=$0" VSS VDD"}1' yourfile
>
> Is this what you want?
>
> --
> D.

Re: selectively add the end of the line

am 17.04.2008 17:27:51 von Bill Marcum

On 2008-04-17, rickm@galaxy.nsc.com wrote:
>
>
> Im sure this one is very easy but I can get want Im after. I have a
> spice file that looks like this:
>
> .subckt CKNXLVTD3 A ZN
> M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> .ends
>
> and it needs to look like this:
>
> .subckt CKNXLVTD3 A ZN VSS VDD
> M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> .ends
>
> Basically, search for .subckt and append VSS and VDD to the line
> only. The line length can be long or short
>
> Thanks
sed '/^\.subckt/s/$/VSS VDD/' file > newfile

Re: selectively add the end of the line

am 17.04.2008 17:29:48 von Dave B

On Thursday 17 April 2008 16:59, rickm@galaxy.nsc.com wrote:

> Im sure this one is very easy but I can get want Im after. I have a
> spice file that looks like this:
>
> .subckt CKNXLVTD3 A ZN
> M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> .ends
>
> and it needs to look like this:
>
> .subckt CKNXLVTD3 A ZN VSS VDD
> M_u2 ZN A VSS VSS nch_lvt w=2.88u l=0.13u
> M_u1 ZN A VDD VDD pch_lvt w=7.62u l=0.13u
> D60 VSS A ndio_lvt AREA=1.65e-13 PJ=1.7e-06
> .ends
>
> Basically, search for .subckt and append VSS and VDD to the line
> only. The line length can be long or short

Uhm...

sed 's/^\.subckt.*/& VSS VDD/' yourfile

or

awk '/^\.subckt/ {$0=$0" VSS VDD"}1' yourfile

Is this what you want?

--
D.

Re: selectively add the end of the line

am 17.04.2008 17:45:54 von Dave B

On Thursday 17 April 2008 17:17, rickm@galaxy.nsc.com wrote:

> Yep, the both work!!!! Can you give a brief description how this
> works. I was only able to print the subckt line.
> What does the trailing "1" do on the awk solution?
>
>> sed 's/^\.subckt.*/& VSS VDD/' yourfile

This says to sed: when a line is like "^\.subckt.*", ie, starts
with .subckt, then substitute that line with the whole line plus
" VSS VDD". Since the -n switch is not specified, sed prints all lines.

>> awk '/^\.subckt/ {$0=$0" VSS VDD"}1' yourfile

This is the same logic applied to awk. Awk reads the file line by line. When
a line is encountered that matches the regular expression ^\.subckt (that
is, a line that begins with .subckt), then add " VSS VDD" at the end of
that line. The "1" is an always-true condition that executes awk's default
action, which is "print the whole line" (ie, $0).
It's equivalent to:

awk '/^\.subckt/ {$0=$0" VSS VDD"}
1 {print $0}' yourfile

Note that any expression that awk evaluates as "true" could be used,
like "hello" or 345. 1 just happens to be the more commonly used choice.

--
D.

Re: selectively add the end of the line

am 17.04.2008 22:26:35 von Michael Tosch

Dave B wrote:
> On Thursday 17 April 2008 17:17, rickm@galaxy.nsc.com wrote:
>
>> Yep, the both work!!!! Can you give a brief description how this
>> works. I was only able to print the subckt line.
>> What does the trailing "1" do on the awk solution?
>>
>>> sed 's/^\.subckt.*/& VSS VDD/' yourfile
>
> This says to sed: when a line is like "^\.subckt.*", ie, starts
> with .subckt, then substitute that line with the whole line plus
> " VSS VDD". Since the -n switch is not specified, sed prints all lines.
>
>>> awk '/^\.subckt/ {$0=$0" VSS VDD"}1' yourfile
>
> This is the same logic applied to awk. Awk reads the file line by line. When
> a line is encountered that matches the regular expression ^\.subckt (that
> is, a line that begins with .subckt), then add " VSS VDD" at the end of
> that line. The "1" is an always-true condition that executes awk's default
> action, which is "print the whole line" (ie, $0).
> It's equivalent to:
>
> awk '/^\.subckt/ {$0=$0" VSS VDD"}
> 1 {print $0}' yourfile
>
> Note that any expression that awk evaluates as "true" could be used,
> like "hello" or 345. 1 just happens to be the more commonly used choice.
>

True with POSIX awk,
but this one is easier and runs on old awk, too:

awk '/^\.subckt/{print $0,"VSS VDD"}' yourfile


--
Michael Tosch @ hp : com

Re: selectively add the end of the line

am 17.04.2008 22:47:51 von Dave B

On Thursday 17 April 2008 22:26, Michael Tosch wrote:

> True with POSIX awk,
> but this one is easier and runs on old awk, too:
>
> awk '/^\.subckt/{print $0,"VSS VDD"}' yourfile

But does this actually print the other lines?

--
D.

Re: selectively add the end of the line

am 21.04.2008 10:29:53 von Michael Tosch

Dave B wrote:
> On Thursday 17 April 2008 22:26, Michael Tosch wrote:
>
>> True with POSIX awk,
>> but this one is easier and runs on old awk, too:
>>
>> awk '/^\.subckt/{print $0,"VSS VDD"}' yourfile
>
> But does this actually print the other lines?
>

You are right, this one returns the other lines, too:

awk '/^\.subckt/{print $0,"VSS VDD";next}{print}' yourfile
or
awk '/^\.subckt/{$0=$0"VSS VDD"}{print}' yourfile

--
Michael Tosch @ hp : com