home *** CD-ROM | disk | FTP | other *** search
- $VER: Newlist8.2 (25-Sep-93) Format help
-
-
- For those of you that do not know how to format a printf() statement for
- use with -F, -C, -M, and -D, this little segment should help.
-
- --------- A Tutorial on How to Make Custom Printf Formats ---------
-
- To form a custom format, you simply make a string of the flags you
- want to appear:
-
- ie nl -F " %n %v"
-
- The above format will display the filename and then the filesize.
-
- ie Aliases.info 597
- Commodore.README 353
-
- Notice how the information is NOT in a columnar format. This is because
- the filename (%n) is of variable length. To make the filename of
- fixed length, you must give the flag %n a numeric qualifier specifying
- how large you want the data to be. This qualifier goes after the %
- and before the meta-character (in this case n).
-
- ie nl -F "%20n %v"
- ^
- length is 20
-
- The above format says to make the name 20 characters no matter
- how short the name is. The output will be like:
-
- ie Aliases.info 597
- Commodore.README 353
- ^
- Starts here
-
- Notice how the output is right justified. To make the data left
- justified, put a minus sign (-) in front of the numeric qualifier.
-
- ie nl -F "%-20n %v"
-
- The output will now look like:
-
- ie Aliases.info 597
- Commodore.README 353
- ^
- Starts here
-
- One disadvantage of the numeric qualifer is that if a file length
- is larger than the fixed length, the output will not be columnized
- anymore.
-
- ie nl -F " %-13n %6v"
-
-
- Times.doc.info 597 <- This name is 14 (larger than 13).
- History 18107 As a result, the output is slightly
- Aliases 2676 messed up.
-
- To fix the problem, you should make the qualifier large. Commodore
- restricts the file length to something like 30 chars, so %-30n will
- ALWAYS work. I prefer to use %-22n since itis small enough for the
- display, yet large enough for most big names.
-
- Or truncation:
-
- If you want to restrict a field to be only X characters long, you
- can give a .x qualifier where x is a number. For example:
-
- nl -F " %.5n"
-
- will output:
-
- Times
- Histo
- Alias
-
- Note how the filenames got truncated to 5 chars. This truncating
- field is very handy for making pseudo-abbreviations. For example:
-
- nl -D "%.3D" will make day name abbreviations
- (Saturday truncated to Sat)
-
-
- You may also mix justification qualifiers with the length restriction
- qualifier. For example:
-
- nl -F " %7.5n"
-
- This says to make the names to be ONLY 5 chars long, then right justify
- this to be 7 chars (add 2 spaces in front).
-
- ----
-
- Now we are not quite done. '%v' is also a variable length field.
- Sometimes it will be 1 or 2 digits (<=99 bytes) or it may be
- very long (100000 bytes etc.). In order for our format to work
- in every case (when files are very big), we should put a large
- qualifier in %v. I would use %6v or %7v to handle even the biggest
- files.
-
- The output will be like:
-
- 555
- 666666
-
- If you would like to have the numeric places held by a 0, then insert
- a zero after the %.
-
- ie nl "%07v"
- ^
- Note that it's NOT %7v
-
- 0000555
- 0666666
-
- ----
-
- One final note: a patron of mine was having problems with his string
- outputs. He was doing the following:
-
- nl -D "%09D"
- ^
- the culprit!
-
- w/ 000Friday
- 0Saturday as outputs.
-
- The reason for the 0's in front of the day name is because of the 0 in
- %09. That 0 tells it to pad the spaces with the 0 character. Thus you
- only want to do this with digit type stuff. To correct the problem above:
-
- nl -D "%9D" <- Notice no leading 0.
-
- w/ Friday
- Saturday as outputs.
-
- Hope that this helps.
- Review the formats in the included alias file
- or consult a C book for info about printf().
-
- Phil Dietz
-
-