Chinaunix

标题: awk1line & sed1line 注解补充版&cheat sheets & perl1line [打印本页]

作者: mwm5    时间: 2009-12-27 10:06
标题: awk1line & sed1line 注解补充版&cheat sheets & perl1line
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 编辑 ]
作者: haimming    时间: 2009-12-27 10:21
赞!
谢!
作者: Shell_HAT    时间: 2009-12-27 14:42
awk1line很好,学习了。
作者: 寂寞烈火    时间: 2009-12-27 16:03
听说还有perl1line
作者: nxlinux    时间: 2009-12-27 17:24
收藏个
作者: Shell_HAT    时间: 2009-12-27 18:40
标题: 回复 #4 寂寞烈火 的帖子
火哥有URL不?我想收藏一下
作者: ghp268    时间: 2009-12-27 20:01
不错!
作者: mwm5    时间: 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
作者: mwm5    时间: 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.
作者: mwm5    时间: 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 ...
作者: Shell_HAT    时间: 2009-12-28 13:04
昨天论坛升级是不是损失了部分数据,发现有些回帖不见了。
作者: mwm5    时间: 2009-12-28 13:17
标题: 回复 #11 Shell_HAT 的帖子
我这看是没少~




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2