<<

. 14
( 69 .)



>>

you to see more of a file in the Terminal window. The
You cannot have four columns, because they would exceed
column command arranges your text lists into columns,
the width of the Terminal window. If the longest line in the
based on the width of your Terminal window. The syntax of
file is 50 characters wide, then you can only have one
the column command is:
column, because you cannot have two columns of 50
characters each within an 80-character Terminal window.
column filename
The column command arranges the items in the list vertically
You can also provide a list to the column command from
in columns. The second item appears under the first item,
another command by piping the output to the column
and continues until you reach the bottom of the first column.
command. For example, if you want to make columns from
The list then continues at the top of the second column. If
the output of the grep command, you can type the
you want your columns to run horizontally instead of
following:
vertically, you can use the -x option with the column
command.
grep 'pattern' filename | column



ARRANGE TEXT IN COLUMNS




– The shell displays the input – The shell displays the input
FILL COLUMNS VERTICALLY FILL COLUMNS HORIZONTALLY
file in columns. file in columns, but in
„ Type column and a space. „ Type column -x and a horizontal order.
space.
¤ Type the name of the
¤ Type the name of the
input file and press Return.
input file and press Return.

55
UNIX FOR MAC




SORTING TEXT
You can instruct the sort command to use alphabetical

Y
ou can sort lines of text by using the sort command.
order instead of character order with the -f option. This
You can eliminate duplicate lines in sorted text by
sorts blue to come before Yellow, because the letter b
using the uniq command. Sorted text is easier to
comes before the letter Y.
read, especially when you are comparing values or locating
a specific word in a list. The sort command makes it easy
Neither way of sorting works well with numbers. All numbers
to do this automatically rather than manually.
beginning with 1 come first, and then numbers beginning
with 2, and so on. So the number 111 comes before the
You can control the sort command by using options, based
number 28, because 111 starts with 1, and 28 starts with 2.
on the type of list you want to sort. By default, the sort
To sort numerically, you can use the -n option with the sort
command uses character order. This seems sensible at first,
command, which then sorts numbers correctly.
except that computers sort uppercase and lowercase letters
in a rather confusing manner. According to your computer,
A similar command to the sort command is the uniq
the alphabet consists of the uppercase letters A through Z,
command. The uniq command takes sorted lines of text,
then the lowercase letters a through z. So the word Yellow
either given as a command line argument or from standard
comes before the word blue, in character order, because all
input, and removes those lines that are duplicates. The
capital letters come before lowercase letters.
command then displays all lines that are unique.

SORTING TEXT




– The shell displays the – The shell displays the
SORT A FILE IN SORT A FILE IN NUMERIC ORDER
CHARACTER ORDER contents of the file, in contents of the file, in
„ Type sort -n and a space.
„ Type sort and a space. character order. numeric order.
¤ Type the name of the file
¤ Type the name of the file to be sorted, and press
you want to sort, and press Return.
Return.



56
4
WORK WITH TEXT


You can use the sort command with the du command to determine which
of your subdirectories are taking up the most space. This can help you plan
your use of disk space when it becomes limited.
The du command lists the size of each directory and subdirectory in blocks;
if you prefer, you can use the -k option to show kilobytes. The first column
of each line displays the size of the file, so you can use the -n option of the
sort command to list the directory sizes in numeric order.

Example:
[ferro:˜] user% du -k Documents | sort -n
0 Documents/Dogs/Sounds
4 Documents/Letters
28 Documents/Dogs
28 Documents/Dogs/Images
56 Documents/To Do Lists
88 Documents
[ferro:˜] user%

The example shows that the smallest directory is the Sounds subdirectory of
the Dogs directory, and the largest is the entire Documents directory itself.




‹ Type a greater-than ‹ Type a vertical pipe, a
SAVE SORTED TEXT ELIMINATE DUPLICATE ITEMS
symbol and the name of a space, then uniq, and press
„ Type sort and a space. „ Type sort and a space.
new file, and press Return. Return.
¤ Type the name of the file ¤ Type the name of the file
– The command sorts the – The command sorts the file
you want to sort, and a you want to sort, and a
contents of the file and saves and removes duplicate lines.
space. space.
the output in the new file.



57
UNIX FOR MAC




PRINT TEXT ON A PRINTER
If you try to print a non-text binary file, two things may

Y
ou can print a file on your printer using the lpr
happen: If the binary file is in a format known to the
command. You can format and print a file on a
printing system, such as a JPEG image file, it prints on your
PostScript printer with the enscript command. The
printer. However, if it is an unknown file format, or an
lpr, or line printer, command sends text directly to your
executable binary file, it may not print at all.
printer. The printer simply outputs the lines, in the order
that it receives them. The syntax for the lpr command is
You can also use the enscript command, which converts
your text file to PostScript. PostScript is a computer
lpr filename
language understood by many printers; you should check
your printer manual to see if it understands PostScript. If it
The lpr command also prints text that is piped from the
does, you can use the enscript command to print text.
standard output of another command:
The enscript command produces better output than the
another command | lpr
lpr command, because PostScript lets you use special
If you do not connect a printer to your computer, the effects. For example, you can place a large, diagonal
lpr command does not work, and you receive an error message, such as Top Secret, in light gray underneath
message. your text. This is known as an underlay, and is set by the
--underlay= option of the enscript command.

PRINT TEXT ON A PRINTER




¤ Type the name of a file ‹ Type lpr and press Return.
PRINT A FILE ON PRINT COMMAND OUTPUT
THE LINE PRINTER and press Return.
„ Type a Unix shell – The printer outputs the
„ Type lpr and a space. – The printer outputs the file. command that displays text text.
output, and a space.
¤ Type a vertical pipe and a
space.

58
4
WORK WITH TEXT



Additional options in the lpr and enscript commands give you
even greater control over the appearance of your printed page. The
-o option of lpr allows you to set specific printing options.

-O OPTION PRINT EFFECT
Print in landscape, or wide, mode.
-o landscape
Print on legal-sized paper.
-o media=Legal
Print on A4, European standard, paper.
-o media=A4
Print two pages per sheet of paper.
-o number-up=2
Print four pages per sheet of paper.
-o number-up=4
Print eight pages per sheet of paper.
-o number-up=8
Print sixteen pages per sheet of paper.
-o number-up=16
Print a header with the date and filename.
-o prettyprint

The enscript command has even more options that you can use to
generate or print PostScript output. For a more complete list, see the
manual page for the enscript command by typing man enscript.




¤ Type the name of a file ‹ Type the name of the file
PRINT A FILE ON A PRINT AN UNDERLAY
POSTSCRIPT PRINTER and press Return. and press Return.
„ Type enscript --underlay=.
„ Type enscript and a space. – The printer prints the file. – The printer outputs the
¤ Type the underlay text in file with the text running
single quotes, and a space.
diagonally beneath it.



59
UNIX FOR MAC




OPEN A FILE WITH PICO
You start the Pico editor by typing pico at the command

Y
ou can edit text files with Pico, a basic and easy-to-use
prompt, along with an optional filename as an argument. If
text editor. The function of a text editor is to enable
the filename argument exists and is a text file, Pico opens
you to open, edit, and save plain-text files. Mac OS X
the file for editing; if it does not exist, you start with a blank
provides several text editors for this purpose. Text editors are
file.
less complex than word processors; they do not allow you to
select fonts, layouts, or other factors that affect the look of
The list of Pico commands appears at the bottom of the
the printed page.
screen. A caret (^) before a letter means that you need to
hold down the Control key while typing a key. For example,
Three shell editors come with Mac OS X; they are Pico, vi,
the notation ^X stands for Control + X.
and emacs. Although they accomplish the same basic task
of editing text, each one has its own strengths and
You can use your keyboard to easily move around in a Pico
limitations. Pico is the simplest to use, because all keystroke
document. You use the arrow keys to move to the position
commands appear on-screen, and there are not many to
you want to insert text, and then start typing. You use the

<<

. 14
( 69 .)



>>