21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

150 <strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>$ date ’+Today is %A, %B %d, %Y.’⊣ Today is Thursday, September 14, 2000.Here is the gawk version of the date utility. It has a shell “wrapper” to handle the ‘-u’option, which requires that date run as if the time zone is set to UTC:#! /bin/sh## date --- approximate the P1003.2 ’date’ commandcase $1 in-u) TZ=UTC0 # use UTCexport TZshift ;;esacgawk ’BEGIN {format = "%a %b %d %H:%M:%S %Z %Y"exitval = 0if (ARGC > 2)exitval = 1else if (ARGC == 2) {format = ARGV[1]if (format ~ /^\+/)format = substr(format, 2) # remove leading +}print strftime(format)exit exitval}’ "$@"8.1.6 Bit-Manipulation Functions of gawkI can explain it for you, but I can’t understand it for you.AnonymousMany languages provide the ability to perform bitwise operations on two integer numbers.In other words, the operation is performed on each successive pair of bits in theoperands. Three common operations are bitwise AND, OR, and XOR. The operations aredescribed in Table 8.6.Table 8.6: Bitwise OperationsBit operatorAND OR XOROperands 0 1 0 1 0 10 0 0 0 1 0 11 0 1 1 1 1 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!