-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHOWTO
142 lines (100 loc) · 2.48 KB
/
HOWTO
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
--
-- Examples for h4sh
--
-- Authors: Don Stewart
-- Thomas Jaeger
--
-- Inspiration for this document based on "HANDY ONE-LINERS FOR SED",
-- compiled by Eric Pement <http://sed.sourceforge.net/sed1line.txt>
--
--
-- Most commands (other than unfolds) read from either a file argument or stdin
--
-- open a file
i
-- first line of a file/pipe (head -1)
hd
-- last line of a file/pipe (tail -1)
last
-- first @n@ lines (head -7)
take 7
-- drop first @n@ lines
drop 7
-- remove the first line
tl
-- remove the last line
init
-- reverse a file (tac)
reverse
-- print a string (echo)
show
-- find lines that match /pattern/ (grep)
filter 'matches "pattern"'
-- find lines that don't match /pattern/ (grep -v)
filter '\s->not(matches"pattern"s)'
-- replace all occurences of string1 with string2
map 'replace "string1" "string2'
-- add a character to the end of each line
map "snoc ','"
-- group lines of input that are equal
group
-- join two files side by side (paste)
zp f g
-- add a new line to the head of a file
cons "The first line"
-- double space a file
intersperse ''
-- an infinite sequence
iterate 'show.(+1).read' 0
unfoldr 'Just. ap(,)(show.(1+).read)' 1
-- a finite sequence
iterate 'show.(+1).read' 0 | take 10
-- repeat a string
rpt str
-- number each line of a file on left
zp <(iterate 'show.(+1).read' 0)
ap 'unlines.zipWith((.(" "++)).shows)[1..].lines'
-- count lines (wc -l)
length
-- remove duplicate lines (uniq)
nub
-- sort
srt
-- join lines of a file
concat
unwords
foldl '(++)'
-- print only lines 65 chars long
filter '(65==).length'
-- print only lines less than 65 chars
filter '(65>=).length'
-- print only lines greater than 65 chars
filter '(65<).length'
-- find all lines that equal "str"
filter '=="str"'
-- remove all lines that equal "str"
filter '/="str"'
-- remove the first occurence of the line "str"
delete str
-- find line 10
index 10
-- find the indices of a given line
indices str
-- reverse each line (rev)
map reverse
-- count lengths of each line
map show.length
-- upper case
map 'map toUpper'
-- lower case
map 'map toLower'
-- remove leading space from each line
map "dropWhile isSpace"
-- remove tailing whitespace
map "reverse.dropWhile isSpace.reverse"
-- center each line of a file
map "\s->(\t->t++s++t)(replicate(div(80-length s)2)' ')"
-- reverse words in a string, but not the string itself
words one two three | map reverse | unwords
-- turn a string into a list of string, suitable for passing to list functions
words one two three