Handy UNIX tips

From b0rken.org
Jump to: navigation, search

Sort two input files to diff (bash):

$ diff <(sort file1) <(sort file2)

Calculate numerical difference between a field in the current line of output and the previous line, in this case field 2. Useful for determining traffic rates from netstat byte counters, for example.

| awk '/obytes/ { if (NR > 1) { print $2 - prev }; prev = $2; }'

Print a list with a pause between every 10 lines...

| perl -pe 'sleep 5 unless $x++%10;$|=1'

...and execute a command for every 10 lines of input

| xargs -L 10 command
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox