免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2030 | 回复: 5

Perl小白求助,如何将如下文本搬到excel里 [复制链接]

论坛徽章:
0
发表于 2017-01-09 14:16 |显示全部楼层
1. Total power consumption
==========================

                                                              Power(Watts)
Power contribution                                      Static  Dynamic    Total
----- ------------                                      ------  -------    -----
Internal power
   Internal register power      240uW    275nW    240uW
   Internal latch power        2.46uW   50.8nW   2.51uW
   Internal memory power           0W       0W       0W
   Other internal power         188uW    451nW    189uW
   Total internal power                                  431uW    776nW    431uW
Pad power                                                   0W       0W       0W
Clock power                                             13.3uW   35.2uW   48.5uW
Inferred Buffer power                                   23.5uW    480pW   23.5uW


Total power                                              467uW     36uW    503uW

2. Total power per supply
=========================

将标绿的部分搬到表格中

论坛徽章:
0
发表于 2017-01-09 15:47 |显示全部楼层

while (<>){
        s/(.*?)([\w|\.]+)\s+([\w|\.]+)\s+([\w|\.]+)$/$1\t$2\t$3\t$4/g;
        print "$_\n";
}

论坛徽章:
0
发表于 2017-01-09 18:55 |显示全部楼层
回复 2# yuxi1988

现在变量进入了$1,$2,$3,$4,怎样一行一行搬到excel里呢

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
发表于 2017-01-09 19:00 |显示全部楼层
你这个文本直接用 Excel 打开,应该就能识别成 csv 格式文件, 另存下不就行了。

论坛徽章:
0
发表于 2017-01-10 08:47 |显示全部楼层
回复 3# junweitao


脚本贴到
to_excel.pl,你的report贴到比如说power.rpt

命令行执行
##$> to_excel.pl power.rpt

然后复制屏幕的输出,贴到excel就可以啦,我试了一下没问题

#to_excel.pl

while (<>){
        s/(.*?)([\w|\.]+)\s+([\w|\.]+)\s+([\w|\.]+)$/$1\t$2\t$3\t$4/g;
        print "$_\n";
}
#power.rpt
Power contribution                                      Static  Dynamic    Total
----- ------------                                      ------  -------    -----
Internal power
   Internal register power      240uW    275nW    240uW
   Internal latch power        2.46uW   50.8nW   2.51uW
   Internal memory power           0W       0W       0W
   Other internal power         188uW    451nW    189uW
   Total internal power                                  431uW    776nW    431uW
Pad power                                                   0W       0W       0W
Clock power                                             13.3uW   35.2uW   48.5uW
Inferred Buffer power                                   23.5uW    480pW   23.5uW


Total power                                              467uW     36uW    503uW

论坛徽章:
0
发表于 2017-01-17 17:02 |显示全部楼层
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::WriteExcel;
my $filename='1.xls';
my $workbook=Spreadsheet::WriteExcel->new($filename);
my $worksheet=$workbook->add_worksheet();
my @a;
while(<DATA>){
if(/^[a-zA-Z]/){
my @b=split /\s{2,}/;
push @a,[@b];
}
}
$worksheet->write_col('A1',\@a);
__DATA__
1. Total power consumption
==========================
                               Power(Watts)
Power     contribution      Static  Dynamic    Total
-----     ------------      ------  -------    -----
Internal  power
Internal  register power     240uW    275nW    240uW
Internal  latch power        2.46uW   50.8nW   2.51uW
Internal  memory power       0W       0W       0W
Other     internal power     188uW    451nW    189uW
Total     internal power     431uW    776nW    431uW
Pad       power              0W       0W       0W
Clock     power              13.3uW   35.2uW   48.5uW
Inferred  Buffer power       23.5uW    480pW   23.5uW
Total     power              467uW     36uW    503uW
2. Total power per supply
=========================
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP