|
|
|
|
|
by angusgr
5036 days ago
|
|
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: $ ps --no-headers -o rss -C chromium | paste -sd+ | bc 793180
|
|