sort - sorts file[s].
Takes list of file-names for input. But piping and redirection also work.
Sends results to screen. So piping or redirection are required.
Do NOT use same file-name for input and output. Date will be destroyed.
sort ofile > newfile
Some Options :
-b - ignore leading blanks. space/tab
-d - dictionary. Puts all upper case words first.
-f - sorts by letter then case. Complement of -d.
-i - ignore non-printable characters.
-n - treat numbers as real numbers not a string of digits.
data | no options | -n |
1 7 23 554 3 |
1 23 3 554 7 |
1 3 7 23 554
|
-o filename - output to specific file-name.
This is the case where you can use the same name as the input.
sort data -o data
-c - check but don't sort. Report first bad line.
-C - check but don't sort. If sorted, return code 0. No output.
-k - key, sort on different 'column', Use , to list multiple -k 3,2
sort -k 2 file
# if file is columns of data, this will sort on the second column.
# uses white space as field delimiter.
-t - define alternative field delimiter.
sort -n -t ":" -k 3 /etc/passwd | less
# uses : as the field delimiter, sorts on 3rd field, keeps numeric order.
-u - unique. eliminate duplicates. Ignores case.
# used with -c, lists first occurrence of duplication. Takes no other action.
uniq - eliminate consecutive duplicate lines.
# use sort -u to eliminate all duplication.
Some Options :
-c - list number of duplications for each line at start of line.
-b - print only duplicate lines.
-u - print only unique lines.
tr - translate. Takes standard input and sends to standard output>
# So redirection and piping required in most cases.
tr takes two lists, the search list and the replacement list.
It does a one to one match on the lists. So lists should be same length.
It does support ranges.
It does support the regex symbolic ranges.
cat data | tr "12345" "ABCDE"cat data | tr "a-z" "A-Z"cat data | tr ":lower:" ":upper:".
Some options :
-d - delete rather than replace, in which case, only single list given.
cat data | tr -d "\r" > ndata # removes the carriage return for DOS text files.
-s - squeeze. If multiple concurrent occurrences of a character listed
in the search set found, replace with single character in the replacement
set.
-c - complement. Translate any characters NOT in the search set.
cat file | tr -c ":alpha:" "-"
ul - underlining. Translates underlines in a document to the
appropriate character for the terminal being used.
If underling not possible, it will strip it from document.
Useful for cleaning up man-pages for printing.
man man | ul -t dumb > man.txt