Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Artifact ID: | af6deefe922839e4ca532e4ad2ba97540186c14b |
---|---|
Page Name: | UnixCommands |
Date: | 2015-05-23 00:36:07 |
Original User: | mwm |
Mimetype: | text/x-markdown |
Parent: | 7490172b967d779cf9dd2f900b67c1f554cdbe59 (diff) |
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 -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.- head - print the first few lines of a file:
eddie -l -L "unlines . take 10"
- tail - print the last 10 lines of a file:
eddie -l -L "unlines . (drop =<< subtract 10 . length)"
- wc - count words (or lines, or characters) in a file:
- count characters with
eddie tshow.length
count words witheddie tshow.length.words
count lines witheddie tshow.length.lines
oreddie -l -L tshow.length
- wc with names - counts as above, but adding the file name.
- count characters with
eddie 'tshow . second length=
count words with'eddie tshow . second (length . words)'
count lines with'eddie tshow . second (length . lines)'
- fgrep - select lines containing a substring:
eddie -l -L 'unlines . filter (isInfixOf "substring")'
- grep - select lines matching a regular expression:
eddie -l -L -m Text.Regex.TDFA -m Text.Regex.TDFA.Text 'unlines . (filter (=~ ("r.e." :: Text)))'
- sort - sort the lines in a file:
eddie -l -L unlines.sort
- Repeat a file
eddie cycle
- Print a file double spaced
eddie -l -L 'unlines . intersperse ""'
- Strip blank lines
eddie -l -L 'unlines . filter (not . null)'
- Map a file to upper case
eddie toUpper
- Strip whitespace from lines in a variety of ways
- From the start of each line:
eddie -l -m Data.Char 'dropWhile isSpace'
From the end of each line:eddie -l -m Data.Char 'reverse . dropWhile isSpace . reverse'
From both ends of a line:eddie -l -m Data.Char 'let f = reverse . dropWhile isSpace in f . f'
- Indent all the lines in a file
eddie -l '(" " ++)'
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.)