Ahot's weblog

Thursday Aug 21, 2008

Forget others commands. Sed is all you need!
Here is some examples how to forget cat, head, tail, grep:
$ cat samplefile
$ sed '' samplefile
1
1
3
4
5

$ cat samplefile | head -3
$ cat samplefile | sed 3q 
1
1
3

$ cat samplefile | tail -3
$ cat samplefile | sed -e :a -e '$q;N;4,$D;ba'
3
4
5

$ cat samplefile | grep 3
$ cat samplefile | sed -n '/3/p
3

$ cat samplefile | grep -v 3
$ cat samplefile | sed '/3/d'
1
1
4
5

$ cat samplefile | uniq
$ cat samplefile | sed '$!N; /^\(.*\)\n\1$/!P; D'
1
3
4
5

$ cat samplefile | wc -l
$ cat samplefile | sed -n '$='
5

And this is not the end. You can ever forget opengl and directX.
Here is source code of tetris game written in sed:
http://uuner.doslash.org/forfun/sedtris.sed
Want to foget something more? Visit sed homepage:
http://sed.sourceforge.net
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

FEEDS:

BOOKMARKS:

This blog copyright 2009 by ahot