March 2002
Beginner
504 pages
10h 47m
English
| 1: | Using the for statement, write an awk script that prints each of the fields in a record in reverse order. |
| A1: | A possible implementation is as follows:
#!/bin/sh
if [ $# -lt 1 ] ; then
echo "USAGE: `basename $0` files"
exit 1
fi
awk '{
for (i=NF;i>=1;i--) {
printf("%s ",$i) ;
}
printf("\n") ;
}' $@
|
| 2: | Write an awk script that balances a checking account. Your program needs to print the balance in the account every time the user makes a transaction. The transactions are stored in a file. Each line or record in the file has the following format: command:date:comment:amount Here date is the date on which the transaction was made, comment is a string (including embedded spaces) describing the transaction, and amount is the amount of the ... |
Read now
Unlock full access