Hour 17

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 ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.