|
|
![]() |
|
|
|
|
||
|
Running Awk Hey, Ted: In the October 19, 2001 issue of Midrange Guru, in the article, "Running Perl On the AS/400 and iSeries," you showed us how to run Perl on the iSeries. Now, tell us how to run awk.
-- Linda If you are at V5R1 or above and have PASE installed, you can run the AIX version of awk through Qshell. The PASE utilities are in directory /QOpenSys/usr/bin. Linda, be aware of two important points:
Here's an example. Suppose you have an ASCII file called phones.txt in the IFS. Each line of the text file contains a name, phone number, and extension. The fields are separated by a colon (:). Phone number and extension may be blank. Bud::275 Curly::290 Larry:(555) 444-3333: Lou:(444) 333-2222:199 Moe::235 Oliver::145 Stanley:(777) 888-9999: If the records are delimited with a linefeed character, this awk command formats the data into columns and writes it to standard output (stdout).
/qopensys/bin/awk '
BEGIN {FS=":"}
{printf "%-15s%-20s%-5s\n",$1,$2,$3}' phones.txt
If records end with the carriage return/linefeed sequence, use sed to strip out the carriage returns.
sed 's/\015//' phones.txt |
/qopensys/bin/awk '
BEGIN {FS=":"}
{printf "%-15s%-20s%-5s\n",$1,$2,$3}'
Here's the output: Bud 275 Curly 290 Larry (555) 444-3333 Lou (444) 333-2222 199 Moe 235 Oliver 145 Stanley (777) 888-9999 -- Ted
|
Editors
Contact the Editors |
|
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |