Transcript Lecture 3
sed -n 2,4p example
sed –n /[aA]gg*[ar][ar]wal/p example
Records in a file in following format
Doe
JOE
897-9090
40 North Bend,
Cincinnati,
Ohio
45212
Smith
marry
345 New Road,
Old City
New York
345689
Doe,
joe
40 North Bend
Cincinnati
Ohio
45122
Spears
Britney
531-6767
1 Star street
Hollywood
CA
78789
Hints for hw2
• Transform record file into canonical form:
– JOE DOE:40 NORTH BEND:CINCINNATI:OHIO:45212
– MARY SMITH:345 NEW ROAD:OLD CITY:NEW YORK: 345689:
etc.
the file has one line per address with fields separated by a
colon
• Addresses are cleaned-up, converted to upper case, sorted
with duplicates removed
Use filters sed, tr and sort to
transform record file. Below are some of
the steps involved.
sed 's/^$/@/' myaddr \
| tr '\012@' ':\012' \
| sed 's/^://;s/:$//' \
| sort –u –t: +0 –3
Use filter awk to convert
transformed canonical file into
desired address labels
Passing Arguments to Shell Programs
• To reference arguments from inside a shell
program use
$i
where i is an integer from 0 to 9.
The name of the script is represent by $0.
$1, $2, …, $9 represent
argument 1, argument 2, …, argument 9.
Number of arguments
• The number of arguments is represented by
argv
• argv[i] represents the ith argument, i.e.,
argv[i] is the same as $i, i = 1, …, 9.