perl程序如何实现将一段文本插入,某一行下方。
例如:将M28(net112innnet036agnd)n33w=4ul=500.0nm=2M29(net108inpnet036agnd)n33w=4ul=500.0n...
例如:
将
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
插入到
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
形式如下:
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2 展开
将
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
插入到
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
形式如下:
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2 展开
2个回答
展开全部
#!/usr/bin/perl
#t.pl
open A,"txt1"; #一段文本
my @a1=(<A>);
while(<>){ #插入文本
if (/I(19|12)/){print $_,"@a1";}
else {print $_}
}
===============
perl t.pl txt2
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
#t.pl
open A,"txt1"; #一段文本
my @a1=(<A>);
while(<>){ #插入文本
if (/I(19|12)/){print $_,"@a1";}
else {print $_}
}
===============
perl t.pl txt2
I19 (AGND AVDD vb_4 net0123 vb_2 vb_3) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
I12 (AGND AVDD vb_4 net0123 vb_2 vb_4) bias
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
更多追问追答
追问
例如:
subckt op2 XXXXXXX
M28 (net112 inn net036 agnd) n33 w=4u l=500.0n m=2
M29 (net108 inp net036 agnd) n33 w=4u l=500.0n m=2
M30 (net036 vs agnd agnd) n33 w=2u l=1u m=4
M27 (net125 vs agnd agnd) n33 w=2u l=2u m=2
M25 (net121 vs agnd agnd) n33 w=2u l=2u m=2
ends op2
首先提取 MM开头的文本,然后插入到I开头的语句后面,请问用perl如何实现?谢谢!!
追答
-----------------------------------------------------------------------------
继续回答
open T,"txt2";
my @a2=grep/^\s*M/,; #提取 MM开头的文本
2011-04-01
展开全部
可以将那段文本放到一个数组里面,然后将数组的内容输出,输出格式如下:
my @insert = 那段文本的列表;
if (/I(19|12)/){
printf ("%60s\n" x @colors), @colors;
}
else {print $_}
}
my @insert = 那段文本的列表;
if (/I(19|12)/){
printf ("%60s\n" x @colors), @colors;
}
else {print $_}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询