home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d597
/
newlist.lha
/
NewList
/
Tutorial.doc
< prev
next >
Wrap
Text File
|
1992-02-01
|
3KB
|
116 lines
For those of you that do not how to format a printf() statement for
use with -F and -df, 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 %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"
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 %v"
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, the only thing you can really do is to 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 it
is small enough for the display, yet large enough for most big names.
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 -ds "%.3t" 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 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
----
Hope that this helps.
Phil Dietz