One I learned for the first time the other day is 'paste'. Good for people like me who never fully grokked awk, it joins lines from separate files into a single file.
Say you have two files, one with lines of numbers:
1
2
3
... and one with letters:
A
B
C
$ paste numbers letters
1 A
2 B
3 C
Want CSV?
$ paste -d, numbers letters
1,A
2,B
3,C
Or, with '-s' you can join lines from inside the same file. For instance, you can sum numbers:
$ paste -sd+ numbers
1+2+3
$ paste -sd+ numbers |bc
6
(Thanks to a Stack Overflow post somewhere for suggesting that one!)
Useful example: the total resident memory size of all chromium processes:
Comments
One I learned for the first time the other day is 'paste'. Good for people like me who never fully grokked awk, it joins lines from separate files into a single file.
Say you have two files, one with lines of numbers:
... and one with letters: $ paste numbers letters Want CSV?$ paste -d, numbers letters
Or, with '-s' you can join lines from inside the same file. For instance, you can sum numbers:$ paste -sd+ numbers
$ paste -sd+ numbers |bc (Thanks to a Stack Overflow post somewhere for suggesting that one!)Useful example: the total resident memory size of all chromium processes:
$ ps --no-headers -o rss -C chromium | paste -sd+ | bc
`paste` is also very useful together with stdin redirection and subshells. E.g.:
They could drift. Better to do a one-ping ping and run iwconfig once in a loop.