selectively add the end of the line

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
RickM [ Do, 17 April 2008 16:59 ] [ ID #1944245 ]

Re: selectively add the end of the line

On Thursday 17 April 2008 16:59, rickm [at] 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.
Dave B [ Do, 17 April 2008 17:29 ] [ ID #1944246 ]

Re: selectively add the end of the line

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 <da... [at] addr.invalid> wrote:
> On Thursday 17 April 2008 16:59, ri... [at] 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.
RickM [ Do, 17 April 2008 17:17 ] [ ID #1944247 ]

Re: selectively add the end of the line

On Thursday 17 April 2008 17:17, rickm [at] 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.
Dave B [ Do, 17 April 2008 17:45 ] [ ID #1944248 ]

Re: selectively add the end of the line

On 2008-04-17, rickm [at] galaxy.nsc.com <rickm [at] 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
Bill Marcum [ Do, 17 April 2008 17:27 ] [ ID #1944249 ]

Re: selectively add the end of the line

Dave B wrote:
> On Thursday 17 April 2008 17:17, rickm [at] 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 [at] hp : com
Michael Tosch [ Do, 17 April 2008 22:26 ] [ ID #1944255 ]

Re: selectively add the end of the line

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.
Dave B [ Do, 17 April 2008 22:47 ] [ ID #1944256 ]

Re: selectively add the end of the line

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 [at] hp : com
Michael Tosch [ Mo, 21 April 2008 10:29 ] [ ID #1946476 ]
Linux » comp.unix.shell » selectively add the end of the line

Vorheriges Thema: chmod g+s file
Nächstes Thema: MD5 checksums from downloaded pdfs to prevent duplication