-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXAMPLES
35 lines (21 loc) · 829 Bytes
/
EXAMPLES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# EXAMPLES
#
# Based on:
# http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt
# http://www.catonmat.net/blog/awk-one-liners-explained-part-one/
(Examples assume input from stdin, and output to stdout, unless
specified otherwise.)
1. Double-space a file:
s1 -e '(out $0) (out "")'
2. Remove empty lines:
s1 -e '(? $0 (out $0))'
3. Double-space a file which already has blank lines in it. Output
file should contain no more than one blank line between lines of text.
s1 -e '(? $0 (out $0) (out ""))'
4. Display lines with the line number in front:
s1 -e '(out ln "\t" $0)'
5. Only number non-blank lines in a file:
s1 -e '(before (def c)) (? $0 (inc! c)) (? $0 (out c "\t" $0) (out $0))'
# TODO: should be MUCH shorter!
6. Count the number of lines in a file:
s1 -e '(after (out nl))'