eddie
Update of ”UnixCommands”
Not logged in
Public Repositories
mwm's Repositories

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 255f0fb1a94f2faa2816907a4962240a1635f575
Page Name:UnixCommands
Date: 2015-03-18 01:23:28
Original User: mwm
Mimetype:text/x-markdown
Next f062a46138dd006e3bb611763651c48b8d1596d8
Content

#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

uniq - remove duplicated lines:
eddie -lL nub will remove all dupliciates. eddie -Ll "map head . group" only works on presorted files, but works in O(n) time.

head - print the first few lines of a file:
eddie -lL "take 10"

tail - print the last 10 lines of a file:
eddie -lLm Data.List.Utils "drop =<< subtract 10 . length"

wc - count words (or lines, or characters) in a file:
count characters with eddie show.length
count words with eddie show.length.words
count lines with eddie show.length.lines

fgrep - select lines containing a substring:
eddie -lL 'filter (isInfixOf "substring")'

grep - select lines matching a regular experssion:
eddie -lLm Text.Regex.TDFA '(filter (=~ "r.e."))'

sort - sort the lines in a file:
eddie -lL sort

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

Repeat a file endlessly.
eddie cycle

Print a file double spaces
eddie -lL 'intersperse ""'

Strip blank lines
eddie -lL 'filter (not . null)'

Map a file to upper case
eddie "map toUpper"

Strip whitespace from lines in a variety of ways
From the start of each line: eddie -l 'dropWhile isSpace'
From the end of each line: eddie -l 'reverse . dropWhile isSpace . reverse'
From both ends of a line: eddie -l 'let f = reverse . dropWhile isSpace in f . f'

Indent all the lines in a file
eddie -l '(" " ++)'