Nice tips of unix command tools

Sort the file by first column. The -n option ensures numeric (as opposed to lexicographic) sort.

Sort the file by second column. The “-k” option here denotes the column used as sort key.

Extract all lines containing the string “33” (in the above example, lines 4 and 5).

Same, but display only the number of matching lines (2 in the example), not the lines themselves. This is useful to analyze large data files of output data. For example, if a sequence of one million integers, is saved as a file, one per line, “grep -c ’33’ file” will display the number of 0’s in that sequence.

Same command, but applied to all files in the current directory matching “*.out”. For each file there is an output line of the form “Filename: x”, where “x” is the number of matching lines in the file.

Sort the file, then prepend line numbers to each line. This results in the following:

http://www.math.uiuc.edu/~hildebr/computer/unixtips.html

Nice tips of unix command tools 123 398…
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *