免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3032 | 回复: 6
打印 上一主题 下一主题

每隔1000行插入一行:commit; 用单行命令怎么写? 单个文件有几百M. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-01 10:56 |只看该作者 |倒序浏览
用  perl -pne 'if($. % 1001 == 0) {print "commit\n"}'   1.sql  


出错
Can't find string terminator "'" anywhere before EOF at -e line 1.

   正确的该怎么写?

论坛徽章:
0
2 [报告]
发表于 2011-03-01 11:27 |只看该作者

  1. perl -lpe 'print "xxx" if $. !=1 && ($. - 1) % 1000 == 0'
复制代码

论坛徽章:
0
3 [报告]
发表于 2011-03-01 11:28 |只看该作者
perl -i -p -e 'if($. % 1000 == 0) {$_ = "$_commit\n"}'   1.sql

试试

论坛徽章:
1
摩羯座
日期:2014-12-29 15:59:36
4 [报告]
发表于 2011-03-01 11:37 |只看该作者
perl -pe 'BEGIN{$a=11}{if($.==$a){print ":commit;\n";$a+=10}}' file

1
2
3
4
5
6
7
8
9
10
:commit;
11
12
13
14
15
16
17
18
19
20
:commit;
21
22
23
24
25
26
27
28
29
30
:commit;
31
32
33

论坛徽章:
0
5 [报告]
发表于 2011-03-01 14:15 |只看该作者
perl -pe 'BEGIN{$a=4}{if($.==$a){print ":commit;\n";$a+=10}}' 1.txt
Can't find string terminator "'" anywhere before EOF at -e line 1.


E:\0011>perl -lpe 'print "xxx" if $. !=1 && ($. - 1) % 3 == 0' 1.txt
% was unexpected at this time.


E:\>perl -i -p -e 'if($. % 10000 == 0) {$_ = "$_commit\n"}'  z_w_cell_daily_kpi.sql
Can't find string terminator "'" anywhere before EOF at -e line 1.


E:\>perl -v

This is perl, v5.10.0 built for MSWin32-x64-multi-thread

Copyright 1987-2007, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

   难道是我的版本有问题?但运行我的其它pl程序不出错!

我的环境,win7 x64,perl是oracle11g x64自带的,它的版本信息见上

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
6 [报告]
发表于 2011-03-01 14:48 |只看该作者
perl -pe 'BEGIN{$a=4}{if($.==$a){print ":commit;\n";$a+=10}}' 1.txt
Can't find string terminator "' ...
blackantt 发表于 2011-03-01 14:15



windows 版,最外面不可用单引号('),要用双引号(")
C:\>perl -v

This is perl, v5.10.1 built for MSWin32-x86-multi-thread
(with 2 registered patches, see perl -V for more detail)


C:\>perl -e 'print "xxx";'
Can't find string terminator "'" anywhere before EOF at -e line 1.

C:\>perl -e "print 'xxx';"
xxx

C:\>perl -e "$a='xxx'; print \"$a\";"
xxx

没事不要用one line command

论坛徽章:
0
7 [报告]
发表于 2011-03-01 15:02 |只看该作者
windows 版,最外面不可用单引号('),要用双引号("
C:\>perl -v

This is perl, v5.10.1 built for ...
jason680 发表于 2011-03-01 14:48



    you are right

perl -lpe "print 'xxx' if $. !=1 && ($. - 1) % 3 == 0"  1.txt
ok

perl -pe "BEGIN{$a=11}{if($.==$a){print \":commit;\n\";$a+=10}}" 1.txt
ok

E:\0011>perl -i -p -e "if($. % 3 == 0) {$_ = \"$_commit,\n\"}"   1.txt
Can't do inplace edit without backup.

thank all
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP