|
5.06 Filter Utilities
Filters
– are commands that output a modified version of their
input (sort and
wc)
sort - sort
lines of text files. (by default will “fold” upper and lower
case characters)
Options:
-b blank # ignores
leading spaces and tabs
-c check # checks
whether files are already sorted and if so, produces no output
-d dictionary # sorts
in dictionary output
-f fold (alphabetically)
# ignores upper/lowercase differences
-g general numeric #
sorts according to general numeric value
-n numeric # sorts
according to a string numeric value
-r reverse # sorts
in reverse order
-tc separate
# separates fields with character defined by c. Default is
tab.
-u unique # sorts
so that identical files in input file appear only once in output
wc - print the number of bytes, words,
and lines in files
Options:
-c bytes # displays
the character count only
-l lines # displays
the line count only
-w words
# displays the word count only
uniq - removes
duplicate lines from a file
Options:
-c count
-d duplicate
-D all duplicate
-i ignore
-u unique
Example:
|
[bash]$
uniq -personal.file |
more |
diff
- compares two files and display
all the difference two files or directories to the screen
head, tail - display
the beginning or the end of a file
Options:
-n num Number
-q quiet
-v verbose
Example:
Using command head to display first 20 lines of the file
|
[bash]$
head -20v personal.file |
dpaste -
merge lines of files
Options:
-d delimiter (reuse
characters form LIST instead of TABS
-s serial – paste
one file at a time instead of in parallel
Example:
|
[bash]$
paste -d',' cats dogs
birds |
cut - removes
sections from each line of files
Options:
-b list bytes
list
-c list characterslist
-d c delimiter
(Default c)
-f list fields
Example: $ cut -c1-19
pets
Example: $ cut -f1,3
pets (columns)
Example:
paste - allows
to combine files
Options:
- replace a
file name with standard input
dchar separates
columns with the char
defined in char instead
of a tab
-s merges lines
from a file one file at a time
|