#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 -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 -l -L "unlines . take 10"`</dd>

<dt>*tail* - print the last 10 lines of a file:</dt>
<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 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 -l -L 'unlines . filter (isInfixOf "substring")'`</dd>

<dt>*grep* - select lines matching a regular expression:</dt>
<dd>`eddie -l -L -m Text.Regex.TDFA -m Text.Regex.TDFA.Text 'unlines . (filter (=~ ("r.e." :: Text)))'`</dd>

<dt>*sort* - sort the lines in a file:</dt>
<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

<dl>
<dt>Repeat a file</dt>
<dd>`eddie cycle`</dd>

<dt>Print a file double spaced</dt>
<dd>`eddie -l -L 'unlines . intersperse ""'`</dd>

<dt>Strip blank lines</dt>
<dd>`eddie -l -L  'unlines . filter (not . null)'`</dd>

<dt>Map a file to upper case</dt>
<dd>`eddie toUpper`</dd>

<dt>Strip whitespace from lines in a variety of ways</dt>
<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>