eddie
Artifact [255f0fb1a9]
Not logged in
Public Repositories
mwm's Repositories

Artifact 255f0fb1a94f2faa2816907a4962240a1635f575:

Wiki page [UnixCommands] by mwm 2015-03-18 01:23:28.
D 2015-03-18T01:23:28.884
L UnixCommands
N text/x-markdown
U mwm
W 2094
#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>

<dt>*head* - print the first few lines of a file:</dt>
<dd>`eddie -lL "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>

<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>

<dt>*fgrep* - select lines containing a substring:</dt>
<dd>`eddie -lL 'filter (isInfixOf "substring")'`</dd>

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

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

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

<dt>Map a file to upper case</dt>
<dd>`eddie "map 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>

<dt>Indent all the lines in a file</dt>
<dd>`eddie -l '("     " ++)'`</dd>
Z 0fb0f2b0e8b0697ff75389f9fdde570a