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
|
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
|
-
+
-
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
+
-
+
-
+
-
-
-
+
+
+
|
#How to implement various Unix commands with eddie.
## Introduction
This is just a list of unix commands (or things that feel like they should be Unix commands) along with a partial implementation of them using eddie.
## The Unix Bestiary
<dl>
<dt>*uniq* - remove duplicated lines:</dt>
<dd>`eddie -lL nub` will remove all dupliciates. `eddie -Ll "map head . group"` only works on presorted files, but works in *O*(n) time.</dd>
<dd>`eddie -l -L unlines.hashNub` will remove all dupliciates. `eddie -L -l "unlines . map headEx . group"` only works on presorted files, but works in *O*(n) time.</dd>
<dt>*head* - print the first few lines of a file:</dt>
<dd>`eddie -lL "take 10"`</dd>
<dd>`eddie -l -L "unlines . take 10"`</dd>
<dt>*tail* - print the last 10 lines of a file:</dt>
<dd>`eddie -lLm Data.List.Utils "drop =<< subtract 10 . length"`</dd>
<dd>`eddie -l -L "unlines . (drop =<< subtract 10 . length)"`</dd>
<dt>*wc* - count words (or lines, or characters) in a file:</dt>
<dd>count characters with `eddie show.length`<br />
count words with `eddie show.length.words`<br />
count lines with `eddie show.length.lines`</dd>
<dd>count characters with `eddie tshow.length`<br />
count words with `eddie tshow.length.words`<br />
count lines with `eddie tshow.length.lines` or `eddie -l -L tshow.length`</dd>
<dt>*wc with names* - counts as above, but adding the file name.</dt>
<dd>count characters with `eddie 'tshow . second length=`<br />
count words with `'eddie tshow . second (length . words)'`<br />
count lines with `'eddie tshow . second (length . lines)'`</dd>
<dt>*fgrep* - select lines containing a substring:</dt>
<dd>`eddie -lL 'filter (isInfixOf "substring")'`</dd>
<dd>`eddie -l -L 'unlines . filter (isInfixOf "substring")'`</dd>
<dt>*grep* - select lines matching a regular experssion:</dt>
<dd>`eddie -lLm Text.Regex.TDFA '(filter (=~ "r.e."))'`</dd>
<dt>NOT WORKING IN 1.0.0 *grep* - select lines matching a regular experssion:</dt>
<dd>`eddie -l -L -m Text.Regex.TDFA 'unlines . (filter (=~ "r.e."))'`</dd>
<dt>*sort* - sort the lines in a file:</dt>
<dd>`eddie -lL sort`</dd>
<dd>`eddie -l -L unlines.sort`</dd>
### The Alternative Bestiary
A collection of commands that do unix-like file processing but don't correspond to a generaly available command (borrowing heavily from http://www.haskell.org/haskellwiki/Simple_unix_tools.)
<dl>
<dt>Repeat a file endlessly.</dt>
<dd>`eddie cycle`<dd>
<dt>Print a file double spaces</dt>
<dd>`eddie -lL 'intersperse ""'`</dd>
<dd>`eddie -l -L 'unlines . intersperse ""'`</dd>
<dt>Strip blank lines</dt>
<dd>`eddie -lL 'filter (not . null)'`</dd>
<dd>`eddie -l -L 'unlines . filter (not . null)'`</dd>
<dt>Map a file to upper case</dt>
<dd>`eddie "map toUpper"`</dd>
<dd>`eddie toUpper`</dd>
<dt>Strip whitespace from lines in a variety of ways</dt>
<dd>From the start of each line: `eddie -l 'dropWhile isSpace'`<br />
From the end of each line: `eddie -l 'reverse . dropWhile isSpace . reverse'`<br />
From both ends of a line: `eddie -l 'let f = reverse . dropWhile isSpace in f . f'`</dd>
<dd>From the start of each line: `eddie -l -m Data.Char 'dropWhile isSpace'`<br />
From the end of each line: `eddie -l -m Data.Char 'reverse . dropWhile isSpace . reverse'`<br />
From both ends of a line: `eddie -l -m Data.Char 'let f = reverse . dropWhile isSpace in f . f'`</dd>
<dt>Indent all the lines in a file</dt>
<dd>`eddie -l '(" " ++)'`</dd>
|