21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

62 <strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>%c This prints a number as an ASCII character; thus, ‘printf "%c", 65’ outputsthe letter ‘A’. (The output for a string value is the first character of the string.)NOTE: The ‘%c’ format does not handle values outside the range0–255. On most systems, values from 0–127 are within the rangeof ASCII and will yield an ASCII character. Values in the range128–255 may format as characters in some extended character set,or they may not. System 390 (IBM architecture mainframe) systemsuse 8-bit characters, and thus values from 0–255 yield thecorresponding EBCDIC character. Any value above 255 is treatedas modulo 255; i.e., the lowest eight bits of the value are used. Thelocale and character set are always ignored.%d, %i%e, %EThese are equivalent; they both print a decimal integer. (The ‘%i’ specificationis for compatibility with ISO C.)These print a number in scientific (exponential) notation; for example:printf "%4.3e\n", 1950prints ‘1.950e+03’, with a total of four significant figures, three of which followthe decimal point. (The ‘4.3’ represents two modifiers, discussed in the nextsubsection.) ‘%E’ uses ‘E’ instead of ‘e’ in the output.%f This prints a number in floating-point notation. For example:printf "%4.3f", 1950prints ‘1950.000’, with a total of four significant figures, three of which followthe decimal point. (The ‘4.3’ represents two modifiers, discussed in the nextsubsection.)On systems supporting IEEE 754 floating point format, values representingnegative infinity are formatted as ‘-inf’ or ‘-infinity’, and positive infinityas ‘inf’ and ‘infinity’. The special “not a number” value formats as ‘-nan’or ‘nan’.%F Like %f but the infinity and “not a number” values are spelled using uppercaseletters.The %F format is a POSIX extension to ISO C; not all systems support it. Onthose that don’t, gawk uses %f instead.%g, %GThese print a number in either scientific notation or in floating-point notation,whichever uses fewer characters; if the result is printed in scientific notation,‘%G’ uses ‘E’ instead of ‘e’.%o This prints an unsigned octal integer.%s This prints a string.%u This prints an unsigned decimal integer. (This format is of marginal use, becauseall numbers in awk are floating-point; it is provided primarily for compatibilitywith C.)%x, %XThese print an unsigned hexadecimal integer; ‘%X’ uses the letters ‘A’ through‘F’ instead of ‘a’ through ‘f’.

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

Saved successfully!

Ooh no, something went wrong!