OSXFAQ Mac OS X UNIX Tip-of-the-Day

Week 101 - Unix Commands Reference (7 March 2005)
by
Adrian Mayo - Editor, OSXFAQ
Friday - Commands to Change File Content
awk ... pattern scanning and manipulation language
Awk reads a text file line by line and applies a series of search, replace, and edit operations to lines that match given criteria.
Awk can read a script file for its processing commands
the language combines a 'C'-like programming language with regular expression search and replace.
(See tips weeks 86 and 87)
gawk, nawk ... variations of awk
Not available in the standard Mac OS X install
sed ... stream editor
Sed reads a text file line by line and applies a series of search, replace, and edit operations to lines that match given criteria
Sed can read a script file for its processing commands
the language uses regular expression search and replace functionality, but lacks the 'C'-like programming language.
(See tips weeks 85 and 89)
tr ... translate on character into another
Reads a text file and translates all occurrences of a given character into another
By default reads and writes standard in and out, so redirection is necessary to work on files
Don't write the output back to the input file, otherwise it will end up empty
col ... strip chars
Col can be used to clean-up files
Option -b to remove multiple backspaces as output by the man pages
Option -x to convert tabs characters to multiple spaces
(See tips week 10)
cut ... filters columns from files
Cut can process a file that has columns of text (for example tab-separated tables) and extract just the specified columns
Option -f to list the columns to be output, like '-f 3,5' for 3 and 5, '-f 3-5' for 3 to 5, or '-f 1,3-5' for 1 and 3 to 5.
Option -d to specify the field separator (by default tab), like '-d " "' for space, or '-d ","' for comma
expand ... expand tabs to spaces
unexpand ... compress spaces to tabs
fmt ... format a text file
Read a file and write a version who's lines do not exceed a maximum specified length, or optionally do not come in under a minimum specified length
Option -c to centre text
Option -p to allow indented paragraphs
Option -s to collapse multiple white space inside lines
fold ... fold long lines
Simple version of fmt which breaks long lines to 80 characters or less
Option -w to specify a maximum width other than 80
If you want to learn more about Mac OS X Unix visit the Learning Center
click.
- For beginners: Mac OS X Unix Tutorials
- For detailed information on specific topics: Advanced Unix
- For OS X in gereral: Mac OS X Tutorials
|