Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I didn't know about the units program. Is there any resource out there that lists these little *nix utility programs?


That's the thing about unix-like systems. No matter how much you have learned there's always some command you don't know.


paste was my most recent "holy shit this saves so much time" discovery. I blame it on the not quite intuitive name.


What do you use it for?


One use is converting columns of numbers into math strings for bc.

Example (contrived):

    $ seq 10 20 | paste -s -d +
    10+11+12+13+14+15+16+17+18+19+20

    $ seq 10 20 | paste -s -d + | bc
    165
Or converting columns of strings into regex 'or' clauses for searching (contrived example again):

    $ cut -f 3 -d , something.csv | paste -s -d "|"
    a|b|c|d|e|f

    $ egrep "$(cut -f 3 -d , something.csv | paste -s -d "|")" another_file
    ... result lines appear here ...


I've used paste all my life, but I never knew you could do

  paste - -
to convert stdin into 2 columns (or "paste - - - -" to get 4 columns!). TIL ...


seq has the -s flag which voids the need of the paste for that command:

  $ seq -s + 10 20
  10+11+12+13+14+15+16+17+18+19+20
But I agree that the paste is very useful.

  # a few random samples for an IN SQL statement
  $ shuf -i 1-500000 -n 5 | paste -s -d ,
  371492,250061,266669,455846,295852

  # we can even get PI
  $ ( seq -s + -f '4/%g' 1 4 100000 && seq -s - -f '4/%g' 3 4 100000 ) | paste -s -d - | bc -l
  3.14157265358979523735


There is a faster way to get pi in bc:

  echo '4*a(1)' | bc -l
(That is, 4×arctan(1)=4×π/4=π.) But your way is truly an awesome use of Unix!


ahah, so that's where R's paste() function comes from...


Together with cut to parse CSV files and e.g. convert a text column into a row.


    ls /usr/bin


Unless `units` doesn't happen to be installed by default, which is the case at least for Arch Linux.

Though it doesn't contain `units` either, here's a Wikipedia list of the standardized (IEEE 1003.1-2008) unix commands. http://en.wikipedia.org/wiki/List_of_Unix_commands


units(1) was in V7, and systems that aren't a superset of V7 are objectively wrong.


Debian same here.


info coreutils is a great place to start.


units is nice, but there isn't much help, and the syntax isn't always easy to remember. It was fun to play with for a while, but wolframalpha.com is better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: