1234567891011121314151617181920212223242526272829303132333435363738 |
- #### arrlen prefixes length to each line of text
- #### license: creative commons cc0 1.0 (public domain)
- #### http://creativecommons.org/publicdomain/zero/1.0/
- #### ive been thinking about the tasks i perform most often in
- #### bash, and of making a few utilities to create shortcuts.
- #### bash is a great language i use every day, though im not an
- #### expert. so these utilities will not replace bash, but for
- #### me they augment it.
- #### they can also be used to teach coding.
- #### the first of these utilities is called arrlen, which takes
- #### stdin and returns the length of each line. yes, you can do
- #### this with a bash one-liner; ive chosen fig.
- # p=$(echo hello | arrlen | awk '{print $1}') ; echo $p
- # 5
- # $ for p in $(echo "hello there how are you?") ; do echo $p ; done | arrlen
- # 5 hello
- # 5 there
- # 3 how
- # 3 are
- # 4 you?
- # $
- function re(z p)
- f=z ; split(f p) ; join(f "") ; return(f)
- fig
- forin (p stdin)
- cr=13 ; chr
- lf=10 ; chr
- z=p ; re(z cr) ; re(z lf)
- p=z ; len ; prints ; " " ; prints
- p=z ; print
- next
|