免费注册 查看新帖 |

Chinaunix

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

awk1line & sed1line 注解补充版&cheat sheets & perl1line [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-27 10:06 |只看该作者 |倒序浏览
Famous Awk One-Liners Explained
http://www.catonmat.net/blog/awk-one-liners-explained-part-one/

Famous Sed One-Liners Explained
http://www.catonmat.net/blog/sed-one-liners-explained-part-one/


cheat sheets
http://www.catonmat.net/download/awk.cheat.sheet.pdf

http://www.catonmat.net/download ... tor.cheat.sheet.pdf

perl1line 见 8-10楼

[ 本帖最后由 mwm5 于 2009-12-28 01:49 编辑 ]

评分

参与人数 1可用积分 +1 收起 理由
r2007 + 1 ^_^

查看全部评分

论坛徽章:
0
2 [报告]
发表于 2009-12-27 10:21 |只看该作者
赞!
谢!

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
3 [报告]
发表于 2009-12-27 14:42 |只看该作者
awk1line很好,学习了。

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2009-12-27 16:03 |只看该作者
听说还有perl1line

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-02-10 06:20:01IT运维版块每日发帖之星
日期:2016-02-11 06:20:00
5 [报告]
发表于 2009-12-27 17:24 |只看该作者
收藏个

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
6 [报告]
发表于 2009-12-27 18:40 |只看该作者

回复 #4 寂寞烈火 的帖子

火哥有URL不?我想收藏一下

论坛徽章:
0
7 [报告]
发表于 2009-12-27 20:01 |只看该作者
不错!

论坛徽章:
0
8 [报告]
发表于 2009-12-27 20:47 |只看该作者

回复 #4 寂寞烈火 的帖子

perl1line应该是说的ibm的dw网站上的2篇文章吧?
功能丰富的 Perl:一行程序 101 - Perl 作为命令行实用程序
http://www.ibm.com/developerWorks/cn/linux/sdk/perl/l-p101/

功能丰富的 Perl:一行程序 102
http://www.ibm.com/developerwork ... l/l-p102/index.html

论坛徽章:
0
9 [报告]
发表于 2009-12-27 20:54 |只看该作者
另外同样是那个blog有一个perl1line注解

http://www.catonmat.net/blog/perl-one-liners-explained-part-one/
http://www.catonmat.net/blog/perl-one-liners-explained-part-two/
http://www.catonmat.net/blog/per ... plained-part-three/

看了下,后头4个,还没有出来。。

    * Part I: File spacing.
    * Part II: Line numbering.
    * Part III: Calculations (this part).
    * Part IV: String creation. Array creation.
    * Part V: Text conversion and substitution.
    * Part VI: Selective printing and deleting of certain lines.
    * Part VII: Release of perl1line.txt.

论坛徽章:
0
10 [报告]
发表于 2009-12-28 01:50 |只看该作者

Tom Christiansen 先生的列表

# run contents of "my_file" as a program
perl my_file

# run debugger "stand-alone"
perl -d -e 42

# run program, but with warnings
perl -w my_file

# run program under debugger
perl -d my_file

# just check syntax, with warnings
perl -wc my_file

# useful at end of "find foo -print"
perl -nle unlink

# simplest one-liner program
perl -e 'print "hello world!\n"'

# add first and penultimate columns
perl -lane 'print $F[0] + $F[-2]'

# just lines 15 to 17
perl -ne 'print if 15 .. 17' *.pod

# in-place edit of *.c files changing all foo to bar
perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c

# command-line that prints the first 50 lines (cheaply)
perl -pe 'exit if $. > 50' f1 f2 f3 ...

# delete first 10 lines
perl -i.old -ne 'print unless 1 .. 10' foo.txt

# change all the isolated oldvar occurrences to newvar
perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]

# command-line that reverses the whole file by lines
perl -e 'print reverse <>' file1 file2 file3 ....

# find palindromes
perl -lne 'print if $_ eq reverse' /usr/dict/words

# command-line that reverse all the bytes in a file
perl -0777e 'print scalar reverse <>' f1 f2 f3 ...

# command-line that reverses the whole file by paragraphs
perl -00 -e 'print reverse <>' file1 file2 file3 ....

# increment all numbers found in these files
perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....

# command-line that shows each line with its characters backwards
perl -nle 'print scalar reverse $_' file1 file2 file3 ....

# delete all but lines between START and END
perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

# binary edit (careful!)
perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape

# look for dup words
perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi'

# command-line that prints the last 50 lines (expensively)
perl -e '@lines = <>; print @lines[ $#lines .. $#lines-50' f1 f2 f3 ...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP