Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Placeholders z/OS UNIX System Services User's Guide SA23-2279-00 |
|
The form of the placeholder %5s tells awk how
to print the associated value. All placeholders begin with % and
end in a letter. The following are some of the most common letters
used in placeholders:
For example, the format string:
contains two placeholders: %s represents a string,
and %d represents a decimal integer.Between the % and the letter at the end of the placeholder,
you can put additional information. If you put an integer, as in %5s, the number is used as a width. awk prints
the corresponding value using (at least) the given number of characters.
Therefore in:
the value of the string $1 replaces the placeholder %5s and is always printed using five characters. The output
is therefore:
as shown before. If you just write:
without the 5, the output is:
If no width is given, awk prints values using the smallest number of characters possible.awk also lets you put a minus sign (–)
in front of the number in the width position. The amount of output
space is the same, but the information is left-justified. For example:
prints:
A placeholder for a floating-point number can also contain a precision. You can write this as a dot (decimal
point) followed by an integer. Specifying a precision tells printf how
many digits to print after the decimal point in a floating-point number.
For example, in:
the placeholder %.2f indicates that printf is
to print all floating-point numbers with two digits after the decimal
point. The output of this program is:
For good-looking output, you might specify
both a width and a precision. For example, the program:
prints the following:
%6.2f indicates that the corresponding
floating-point value should be printed with a width of six characters,
with two characters after the decimal point.Here are a few more awk programs that work on the hobbies file. Predict what each prints and run them
to see if your prediction is right:
|
Copyright IBM Corporation 1990, 2014
|