0% found this document useful (0 votes)
14 views

Unix Unit 2 Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Unix Unit 2 Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

I

Simpl~ Fi_lters
This chapter features the simple filters of the system-commands which accept data from standard
input, manipulate it and write the results to standard output. Filters are the central tools of the
UNIX tool kit, and each filter featured in this chapter performs a simple function. This chapter
shows their use both in standalone mode and in combination with other tools using redirection
and piping.
Many UNIX files have lines containing fields-strings of cha~acters representing a meaningful
entity. Some commands expect these fields to be separated by a -suitable delimiter that's not used by
the data. Typically this delimiter is-.a : (as in /etc/passwd and $PATH), but we have used the I (pipe)
as delimiter for some of the sample files in this and other chapters. Many filters work well with
delimited fields, and some simply won't work without them.
WHAT You WILL LEARN
• Use pr to format text to provide margins and headers, doublespacing and multiple column
output. • •
• Pick up lines from the beginning with head, and from the end with ta11.
• Extract characters or fields with cut.
• Join two files laterally, and multiple lines to a single line with paste.
• Sort, merge and remove repeated lines with sort.
• Find out the unique and nonunique lines with uniq.
• Change, delete or squeeze individual characters with tr.

TOPICS OF SPECIAL INTEREST


• A special feature of paste to form a singe line fr~m multiple lines.
• the counting facility available in uniq.
• Use all of these commands in an example to perform content manipulating tasks .
• I ;, .. , •
/

k2~ UNIX: Concepts and Applications


-------------------------
Fdters Reviewed ftld
• tageO 1 d
Filters were introduced in Section 8.5.4 as a category of commands that take a van tandafd
redirection features. A filter has the capability of reading standard input and writing t~oift a
By default, a filter writes to standard output. It reads from standard input when used
as argument, and from the file otherwise. • d.
standaf &VJ
The piping mechanism of the shell lets the standard output of one filter serve as ho'wSlhi
5
another. This feature lets us design pipelines containing a series of filters. Section 12. l n't 00 ~
in combination for performing content manipulations tasks-tasks which these toO s ca
acting alone.

12.1 THE SAMPLE DATABASE


Henceforth, you'll be learning the features of several UNIX commands, including _theadv~-
ones, text editing and shell programming with reference to a file emp. 1st. It's a good idea to '
close look at the file now and understand the organization:
1
$ cat e11p.lst •
2233la,k. shukla lg.m. Isales 112/12/5216000
9876lja1 shanna I di rector I production I 12/03/50 I 7000
.!
5678lsumit chakrobartyld,g.m. !marketing 119/04/4316000
,,
I
2365lbarun sengupta !director !personnel 111/05/47'7800
5423ln,k. gupta lchainnan ladmin 130/08/5615400
1006lchanchal singhvi I director Isales 103/09/3816700
62131 karuna ganguly Ig.m. I accounts I 05/06/62 I 6300
1265ls,n. dasgupta !manager Isales 112/09}6315600
4290ljayant Choudhury lexecuti ve I production I 07 /09/50 I 6000
2476lani1 aggarwal !manager Isales jOl/05/59I5000
652lllalit chowdury !director !marketing 126/09/4518200
3212lshyam saksena - jd.g.m. Iaccounts I 12/12/55 I 6000
35641 sudhi r Agarwal I executive I personnel I 06/07/47 '7500
2345lj,b~ saxena lg,m. !marketing I 12/03/45I8000
OllOlv,k. agrawal lg,m. lmarketi ng I 31/12/40 I 9000

This is a text file designed in fixed format and containing a personnel database. There arc 151'r
in the file, where each line has six fields separated from one another by the delimiter 1- Thedrol
of an employee arc stored in one line. A person is identified by the emp-id, name, dcsigoatn
department, date of birth and salary, as indicated by the fields (in the same order). You'll bcwil
~is ~les, ~r ones derived from them, in various ways to see the extent of manipulation tb;
possible with the UNIX tool kit. ;1
\ '
Simple Filters ~29 I
12.2 pr: PAGINATING FILES
The pr command prepares a file for printing by adding suitable headers, footers and formatted
text. A simple invocation of the command is to use it with a filename as argument:
$ pr dept.1st

May 06 10:38 1997 dept. l st Page 1


Ol:accounts:6213 These six lines are the original contents of
02:admin:5423 dept.1st shown in Section 5.1
03:marketing:6521
04:personnel:2365
05:production:9876
06:sales:1006
...blank lines...
pr adds five lines of margin at the top and five at the bottom. The lower portion of the page has not
been shown in the examples for reasons of economy. The header shows the date and time of last
modification of the file along with the filename and page number.

12.2. 1 pr Options
pr's -k option (where k is an integer} prints in k columns. If a program outputs a series of 20
numbers, one in each line, then this option can make good use of the screen's empty spaces. And
because pr is a filter, it can obtain its input from the standard output of another program. Let's use
the -t option also to suppress the headers and footers:
$ a.out I pr -t -5
0 4 8 12 16
1 5 9 13 17
2 6 10 14 18
3 7 11 15 19
If you are not using the -t option, then you can have a header of your choice with the -h option.
This option is followed by the header string. There are some more options that programmers will
find useful:
• -d Doublespaces input, reduces clutter.
• -n Numbers lines, helps in debugging code.
• -on Offsets lines by n spaces, increases left margin of page.
Combine these various options to produce just the format you need:
$ pr -t -n -d -o 10 dept.1st
1 01:accounts:6213
2 02:admin:5423
G3ol UNIX: Concepts and Applicatiol)S

3 03:marketing:6521
4 04:personnel:2365
5 05:production:9876
6 06:sales:1006
There's one option that uses a number prefixed by a+ to print from a specific page numbctAo,,
option (-1) sets the page length: •
pr +10 chapOl Starts pn'ntingfrom page 10
pr -1 54 chapOl Page length set to 54 lines
Because pr formats its input by adding margins and a header, it's often used as a "pre-pr~
before printing with the lp command:
pr -h "Department list" d~pt.lst I lp Use l pr in Linux
Since pr output often lands up in the hard copy, pr and 1p form a common pipeline sequCltt

Note: fur numbering lines, you can also use the nl command (not covered in this edition). ft'seai(

12.3 head: DISPLAYING THE BEGINNING OF A FILE


The head command, as the name implies, displays the top of the file. When used wiui111 •
option, it displays the first ten lines of the file:
head emp. l st Shows first ten lines
You can use the -n option (POSIX mandated) to specify a line count and display, say, the filll
lines of the file:
Shead -n 3 ~.1st Or head -3 emp. l st on some rystttrJ
22331a.k. shukla jg.m. Isales 112/12/5216000
9876 jai sharma !director lproductionl12/03/50l7000
5678 sumit chakrobartyjd.g.m. !marketing j19/04/43l6000
head can be used in imaginative ways. Consider that you are resuming an editing sessionuii
day and find that you are unable to recall the name of the file you last edited. Since ls -tdii
filenames in orderof their modification time, the job is easily done by picking up the firstfil(m;
from the list and using it as an argument to vi. This requires command substitution:
vi ·1s -t I head -n 1· Opens last modifiedfile for td,iing •
You can define this as an alias (10.4) so the aliased command is always available for you tout
Simple Filters 231 I
12.4 tail: _DISPLAYING THE END OF A FILE
Complementing its head counterpart, the tail command displays the end of the file. It provides an
additional method of addressing lines, and like head, it displays the hist ten lines by default. The
last three lines are displayed in this way:
$ tail -n 3 emp.lst Or11setail -3 emp.lst
3564lsudhir Agarwal lexecutivelperso nnel 106/07/4717500
2345lj,b. saxena lg.m. Imarketing 112/03/4518000
OllOlv,k. agrawal lg,m. Imarketing 131/12/4019000
You can also address lines from the beginning of the file instead of the end. The +count option
allows you to do that, where count represents the line number from where the selection should
begin. Since the file contains 15 lines, selecting the last five implies using
tail +11 emp. l st 11th line onwardf, possible with+ symbol

12.4.1 tail Options


tail has more options than head, and can also extract in units of bytes rather than lines.
Monitoring File Growth (-f) Many UNIX programs constantly write to the system's log files as
Jong as they are running. System administrators need to monitor the growth of these files to view
the latest messages. ta i 1 offers the -f (follow) option for this purpose. This is how you can monitor
. the installation ofOracle by watching the growth ofthe log file ins ta 11.1 og from another terminal:
tail -f /oracle/app/ora cle/product/8.1 /orainst/install . log
The·prompt doesn't return even after the work is over. With this option, you have to use the
interrupt key to abort the process and exit to the shell.
Ertracting Bytes Rather than Lines (-c) POSIX requires tail to support the -c option followed
by a positive or negative integer depending on whether the extraction is performed relative to the
beginning or end of a file. Solaris supports this option only in its XPG4 version, but this is no
problem in Linux:
tail -c -512 foo Copies last 512 bytes from foo
tail -c +512 foo Copies everything after skipping 511 bytes

Tip: Use tai 1 -f when you are running a program that continuously writes to a file, and you want to see
how the file is growing. You have to terminate this command with the interrupt key. •

12.5 cut: SLITTING A FILE VERTICALLY


The features of the cut and paste commands will be illustrated with specific reference to the file
short 1i st, which stores the first five lines of emp. l st:

J
@ UNiX: Concepts and Applications

$ head -n 5 emp .1st I tee short11 st I

2233la,k. shukla lg,m. Isales 112/12/5216000


9876ljai shanna !director productionl03/12/50 7000
5678lsumit chakrobartyld,g.m. marketing 04/19/43 6000
2365lbarun sengupta !director personnel I0S/11/47 7800
5423ln,k. gupta lchainnan ladmin I0S/30/5615400
Note the use of the tee facility that saves the output in shortlist and also displays ilct
terminal. Vk can extract both columns and fields from this file with the cut command.
arc specified with the -c option and fields with -f. We'll take up columns first.

• 12.5.1 Cutting Columns (-c)


To extract specific columns, you need to follow the -c option with a list ofcolumn numbers,
by a comma. Ranges can also be used using the hyphen. Here's how we extract the n2Q"ic
designation from short1i st:
S cut -c 6-22.24-32 shortlist
a.k. shukla g.m.
jai shanna di rector
sumit chakrobartyd.g.m.
barun sengupta director
n.k. gupta chairman
Note that there should be no whitespace in the column list. Moreover, cut uses a special fo~
sdecting a column from the beginning and up to the end of a line:
cut -c -3,6-22,28-34,55- shortlist Must be an ascending list
The expression 55- indicates column number 55 to end of line. Similarly, -3 is the same asl-l

12.5.2 Cutting Fields (-f)


The -c option is useful for fixed-length lines. Most UNIX files (like / etc/passwd and /etc/grt;
don't contain fixed-length lines. To extract useful data from these files you need to cut fields
than columns. cut uses the tab as the default field delimiter, but can also work with a •
delimiter. Two options need to be used here: -d for the field delimiter and -f for the field list.
is how you cut the second and thi~d fields of our sample file:
S cut -d \I -f 2,3 shortlist I tee cutlistl
a.k. shukla g.m.
jai shanna director
sumit chakrobarty d.g.m.
barun sengupta director
n.k. gupta chainnan
The I was escaped to prevent the shell from interpreting it as the pipeline character; altemini
it can also be quoted (-d" I"). To cut out fields numbered 1, 4, 5 and 6 and save the OU!pl
cutl i st2, follow a similar procedure:
cut -d •1• -f 1,4- shortlist> cutlist2 Here' I is quoted
Simple Filters

Extracting User List from who Output cut can be used to extracl the first word of a line by
specifying the space as the delimiter. The example used in Section 3.10 now run in tandem with
cut displays the list of users only:
$ who I cut -d • • -fl Space is the delimiter
root
kumar
shanna
project
sachin
cut is a powerful text manipulato r often used in combination with other commands or fiJters.
You'll be using the command a number 9f times in this text.

Note: You must indicate to cut whether yop are extracting fields or columns. One of the options -f and
-c must be specified. These options are r lly not optional; one or them is compulsory.

12.6 paste: PASTING FILES


What you cut with cut can be pasted back with the paste command- but vertically rather than
horizontally . You can view two files side by side by pasting them. In the previous topic, cut was
used to create the two files cut l is tl and cutl i st2 containing two cut-out portions of the same file.
Using paste, you can fix them laterally:
$ paste cutlistl cutlist2
a.k. shukla jg.m. 2233jsales ll2/12/52j60 00
jai shanna !director 9876jproduc tionl12/03/5 0j7000
sumit chakrobarty jd.g.m. 5678jmarket ing 119/04/4316000
barun sengupta !director 2365jperson nel lll/05/47178 00
n.k. gupta jchairman 5423ladmin l30/08/56j54 00
The original contents have been restored to some extent, except that the fields have different relative
locations, and pasling has taken place on whitespace. Like cut, paste also uses the tab as the
default delimiter, but you can specify one or more delimiters with -d:
$ paste -d•j• cutlistl cutlist2
a.k. shukla lg.m. l2233lsales 112/12/5216000
jai sharma !director j9876lprodu ctionjl2/03/ 50l7000
sumit chakrobarty jd.g.m. l5678lmarke ting l19/04/43l60 00
barun Sengupta !director j2365jperson nel lll/05/47178 00
n.k. gupta • lchainnan l5423ladmin 130/08/5615400
Even though paste uses at least two files for concatenatin g lines, t~e data for one file can be supplied
through the standard input. If, for instance, cutl i st2 doesn't exist, you can provide the character
stream by cutting out the necessary fields from shortlist and piping the output to paste:
$ cut -d \I -f 1.4- shortlist I paste -d •1• cutlistl -
a.k. shukla jg.m. l2233jsales 112/12/52l60 00
j~j shanna !director l9876jprodu ctionl12/03/ 50l7000
12341 UNIX: Concepts and Application s
j

sumit chakrobartyld.g.m. l5678lmark eting 19/04/43 I 6000.


barun sengupta !director l2365lpers onnel 111/05/4717 800
n. k. gupta Ichairman I 5423 I admi n 130/08/561 5400
You can also re_verse the or4erof pasting by altering the location of the - sign:
I

cut -d "I" -f 1,4- shortl1st I paste -d "I" - cutlistl


Joining Lines (-s). paste is more useful than you might think. Consider this addrcssbfx.lj
contains details of three persons, with three lines for each:
$ cat addressbook
anup kumar Name
anup kPyahoo.com Email address
24569083 Telephone number
vinod sharma
vinod [email protected]
34586532
madhuri bahl
[email protected]
39034943
The -s option joins lines in the same way vi's J command docs (7.5.4). Using this option111
r file (with paste -s addressbook) would join all of these nine lines.to form a single line. Thin,
be of much use, so we'll learn to use the -d option with multiple delimiters to join three lincsallb
Ifwe specify the delimiter string as 11 \n with -d, the delimi tcrs are used in a circular mannctl
first and second lines would be joined with the I as delimiter, and the same would be truc"1
second and third line. The third and fourth line would be separated by a newline. After them
exhausted it is reused. This is exactly what we want:
$ paste -s· -d•ll\n• addressbook
anup [email protected]
vinod [email protected]
[email protected]
Just see how paste works (with a single file this time) to concatenat e lines in a specified 111-lt!
Table data is often split with each column on a separate line, and it's in situations like thcscl
paste can be so useful.

12.7 sort: ORDERING A FILE


Sorting is the ordering of data in ascending or descending sequence. The sort command ordc
file. Like cut, it identifies fields and it can sort on specified fields. We'll consider the impart
sort options by sorting the file shortl t st (created in Section 12.5) in different ways. By tk&i
the entire line is sorted:
S sort shortlist
2233la.k. shukla lg.m. Isales 112/12/5216000
236Sjbarun sengupta !director !personnel 11/05/47 7800
Simple Filters ~
35
I
5423ln.k. gupta lchainnan ladmin 130/08/5615400
5678lsumit chakrobartyld,g.m. !marketing 119/04/4316000
9876jjai shanna !director jproductionj12/03/50l7000
• I
By default, sort reorders lines in ASCII collating sequence-wh itespace first, then numerals,
uppercase letters and finally lowercase letters. This default sorting sequence can ~e altered by
using certain options. You can also sort on one or more keys (fields) or use a different ordering rule.

12,7 .1 sort Options


The important sort options are summarized in Table 12.l. We'll be using the -k (key) POSIX
option to identify keys (the fields) instead of the +n and -n forms (where n is the field number) that
were used earlier. Unlike cut and paste, sort uses one or more contiguous spaces as the default
field separator (tab in cut and paste). We'll use the -t option to specify the delimiter.
Sorting on Primary Key (-k) Let's now use the -k option to sort on the second field (name). The
option should be -k 2:
$ sort •t•1• -k Z shortlist
2233 a.k. shukla lg.m. Isales 12/12/5216000
2365 barun sengupta !director [personnel 11/05/4717800
9876 jai shanna !director !production 12/03/5017000
5423 n.k. gupta lchainnan ladmin 30/08/5615400
5678 sumit chakrobartyjd.g.m. !marketing l19/04/43j6000
The sort order can be reversed with the -r (reverse) option. The following sequence reverses a
previous sorting order:
$ sort •t•1• -r -k Z shortlfst
5678lsumit chakrobartyjd.g.m. !marketing 119/04/4316000
5423jn.k. gupta lchainnan ladmin 130/08/5615400
9876ljai shanna !director lproductionl12/03/50l7000
2365lbarun sengupta !director !personnel lll/05/4717800
2Z33la.k. shukla lg.m. Isales 112/12/5216000
sort combines options in a rather unusual way. The previous command sequence could also have
been written as:
sort -t•1• -k Zr shortlist
Sorting on s~condary Key You can son on more than one key, i.e., you can provide a secondary
key to sort. Ifthe primary key is the third field, and the secondary key is the second field, then you
need to specify for every -k option, where the son ends. This is done in this way:
$ sort -t•1• -k 3,3 -k z,z shortlist
5423 n.k. gupta lchainnan \admin 130/08/5615400
5678 sumft chakrobartyld,g.m. marketing 119/04/4316000
2365 barun Sengupta Idirector !personnel lll/05/4717800
9876 jai shanna ldirector lproductionll2/03/50l7000
22l3 a.k. shukla lg,m. Isales l12/12/52j6000
!
G.i,~ UNIX: Concepts and Applications

This sorts the file by designation and name. - k 3 • 3 indicates that sorting starts on the thirJ
and ends on the same field.
Sorting on Columns You can also sp~cify a charactbr position within a field to be the be~
ofsort. If you are to sort the file according to the year/of birth, then you need to sort on the
and eighth column positions within the fifth field:
$ sort -t•j• -k 5.7.5.8 shortlist
5678lsumit chakrobartyld.g .m. !marketing 19/04/4316000
23651 barun sengupta Idi rector Ipersonnel 11/PS/4717800
9876ljai shanna !director !production 12/03/50l7000
2233 Ia. k. shukl a Ig .m. Isales I 12/12/52 I6000
5423ln.k. gupta lchainnan ladmin 13_0/08/5615400
The -k option also uses the form -km .n where n is the character position in the mth fi<~I
5.7,5.8means that sorting starts on column 7 of the fifth field and ends on column 8.
Numeric Sort (-n) When sort acts on numerals, strange things can happen. Whenyousonal
containing only numbers, you get a curious result: •
$ sort numfile
10
2
• 27
' 4

This is probably not what you expected, but the ASCII collating sequence places 1aboit.
and 2 above 4. That's why 10 preceded 2 and 27 preceded 4. This can be overridden byrk-
(numcric) option:
$ sort -n n1111ftle
2
4
10
27
&moving Repeated Lines (-u) The -u (unique) option lets you remove repeated lincsfioo
file. If you "cut" out the designation field from emp.1 st, you can pipe it to sort to find mii
unique designations that occur in the file:
$ cut -d•I• -f3 eap.lst I sort -u I tee destgx.lst
chainnan
d.g.m.
di rector
executive
g.m.
manager
We used three commands to solve a text manipulation problem. Herc, cut select the thirtl6i
from shortl 1st forsort to work on. -

Simple Filters ,r
I
mi
Other sort Option s Even thoug h sort's output can be redirected to a file, we can use' its -o
filenam es can even
option to specif y the outpu t filenam e. Curiou sly enoug h, the input and output
• . '
be the same:
sort -o sorted l i st -k 3 short list Outpu t stored in sorted l i st •
sort -o short list short list Outpu tstored insam efile
the -c (check ) option :
To check wheth er the file has actual ly been sorted in the defaul t order, use
$ sort -c short list
$ File i.s sorted
field is sorted:
. You can also add the -k option to the above to check wheth er a specific
$ sort -t•1• -c -k Z short list
sort: short list:2 : disord er: 2365lb arun sengup ta !direc tor !perso nnel 111/05 /4
717800
them and sorts them
When sort is used with multip le filenam es as argum ents, it concat enates
suffers. The -m (merge )
collectively. When large files arc sorted in this way, perfor mance often
option can merge two or more files that are sorted individ ually:
sort -m fool foo2 foo3
only if the three files are
This comm and will run faster than the one used withou t the -m option
sorted .

Tip: Comm it to memo ry the defaul t delimit er used by cut, paste and
sort. cut and paste use the tab,
but sort uses a contig uous string of spaces as a single delimiter.

'lablc 121 sort Option s


Optio n Descr iption
-tchar Uses delimi ter char to identif y fields
-kn Sorts on nth field
-km.n Starts sort on mth field and ends sort on nth field
-km.n Starts sort on nth colum n of mth field
-u Remov es repeat ed lines
-n Sorts numer ically
-r Reverses sort order
-f, Folds lowerc ase to equiva lent upperc ase (case-insensitive sort)
-m list Merge s sorted files in list
•C Check s if file is sorted
-ojlna me Places outpu t in file flname
I
I
Simple Filters

/ementing Values ofExp~esSion (-c) Finally, ·the -c (compl ement) option comple ments the
C0111{,haracters i~ the expresSlOn. Thus, to delete all characters except the I and/, you can combin e
set 0 d -c options : .
the -d an
cd , I/ ' <emp. 1st
1, HIi 11111 / / 1111' ,' ( ( ,' ,1)) ,' ( /.11111 / / I I I 11 / / I I I I II/• 11111 / / 11111 / / 11111 / / 11111 / / 1111 .
l//11111//11111/ -
ance
• l output indeed! tr has deleted all charact ers except the I and / from the file. The appear
• d. d f
Vnusua th
th rornpt at e imme iate en °
output shows that the newlin e charact er has also not been
of edp We'll use the -c and. -d optibns to place each word in a separat e line in our examp_le
spare • .
·on (12.10).
secU
• ASCII Octal Values and Escape Sequences Like echo, tr also uses octal values and escape
c ·1· · y suited for using nonprintab le c h aracter s
• speciall
uences to represe nt c h aracter s.
V.1ing Th"1s 1ac1 1ty 1s
::ie expression. So to have each field on a separat e line, replace the I with the LF charac
ter (octal
value 012):
$ tr • I ' '\012' < emp. 1st I head -n 6 Can also use \ n
instead of\012
2233
a.k. shukla
g.m.
sales
12/12/52
6000
s
Ifyou reverse the two expressions, you'll make the newline charact er ~isible. Study these tr option
of the tr
closely, and you'll discover many areas where you can apply them. We'll be using some
• •
options in the exampl e that's conside red next.

12.10 AN EXAMPLE: DISPLAYING A WORD -COUN T LIST


that uses a
Armed with the knowle dge of the basic UNIX filters, let's devise a comma nd sequen ce
s the
number of filters in a pipelin e. Docum ent authors sometim es like to view a list that display
has to be
frequency of usage of each word in the docume nt. For this to be possible, each word
newlin es:
placed in a separat e line. tr can do that by convert ing all spaces and tabs (octal 011) to
tr 11
\012\012 11 < fool Space is \040
a word
There's a space before \011; we won't be display ing the symbol subsequently. If we define
habetic
as a contiguous group of alphabe tic characters, we have to use tr again to delete all nonalp
s the use
characters (apart from the newlin e) from the output of the first tr comma nd. This require
ofthe comple mentar y (-c) and delete (-d) options :
tr• ~011• u\012\012" < fool tr -cd "[a-zA-~\012]" . .
.
pipe it to
You now have a list ofwords, with each word on a separat e line. Now sort this output and
•tq -c: . . .·
UNIX: Cance_pts a_nd Ap
... ~d
plications
$ tr " \011" "\012\012"
32 Apache
< ~~ol tr -cd II [a-zA-Z\012]
n l so;t I un;q -c
18 ONS pac e used 32 times
10 Directory
16 FQDN
25 addresses
56 directory
Ycou had to use four commands to disp
reverse numeric sequen . lay the word count. Y
ce and pnnt 1t. 1n
.
three ~olumns..
ou'll need two more to
son h .
$ tr " \011" "\012\01 t elir
2" < fool I tr -cd -
> \s o rt -nr \ pr -t "[a-zA-Z\012]" I sort I uniq -c \
56 di rectory
-3
32 Apache 25 addresses •
18 ONS 16 FQDN
For the sake of readab 10 Di rectory
ility, we split the com
[Enter] key. mand line into two lin
es by using\ to escape~,
12.11 CONCLUSION
Th is ch ap te r presen
ted some of th e com
filters mostly w or k monly used filters av
on entire lines or fie ai la bl e in th e U N IX
Th es e filters have lim lds; it's on ly tr th at system. Thtst
ited use w he n they ar m an ip ul at es indivi
of th em in pipelines e us ed in st an da lo ne du al characters.
to perform tasks th at m od e. B ut yo u also
means. We still have apparently se em so used a number
four other filters to di difficult to achieve
deviate from th e do sc us s- -g re p, sed, aw by convention~
-one-thing-well appr k an d perl, bu t three
II
oach to U N IX tool of them actually
bu ild in g.

You might also like