Processing text using filters

File-combining commands

cat: concatenate; combine an arbitrary number of files and send it to a file. It’s also commonly used to display the content of short files.

Options for cat:

-E –show-ends see where line ends
-n –number add numbers to the beginning of every line
-b –number-nonblank numbers only lines that contain text
-s –squeeze-blank compress groups of blank lines down to a single one
-t –show-tabs display tabs as ^I

tac: it reverses the order of lines in the output.

join: combines two files matching the content of specified fields. Fields are usually separated by a space. -t [char] option lets you specify another character to be used as separator.

paste: merges file line by line, separating the lines from each file with tabs.

File-transforming commands

expand: convert tabs with spaces; by default it assumes a tab stop every 8 characters.

od: octal dump, used for files that don’t use ASCII.

sort: sort an output in several ways, -f -ignore-case, -M –month-sort (3-letter month abbreviation), -n –numeric-sort, -r -reverse

split: you have to specify a fine name (a prefix) and how large you want the individual files, option -b [size]

unexpand: convert spaces into tabs

uniq: remove duplicate lines

File-formatting commands

ftm: tries to clean up paragraphs (it assumes are delimited by two or more blank lines) and limits them to 75 characters

nl: adds numbers to the non-blank lines in a file

pr: format text for printing (80 characters length), -d –double-space, –l [lines] length of the page in lines, -h [text] set header

File-viewing commands

head: echoes the first 10 lines of a file, -n [num] –lines=[num]

tail: shows the last 10 lines of a file, -n [num], -f –follow keep the file open and display new lines as they are added, –pid=[pid] terminate tracking once a process with that PID terminates

less

File-summarizing commands

cut: extracts portions of input lines and displaying them to STDOUT. This command is frequently used in scripts to extract data from other commands.

wc: word count, display [lines] [words] [bytes]

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.