I have a script that modifies all files in a directory and outputs in terminal the status of the modifications in real time, like this example:
Modifying json.php... MODIFIED
Modifying layout.php... ERROR
Modifying a_very_long_named_file.php... NOT MODIFIED
I’m wondering if there is some command I can use to echo like in an ordered book’s index, like this:
Modifying json.php..........................MODIFIED
Modifying layout.php........................ERROR
Modifying a_very_long_named_file.php........NOT MODIFIED
You can probably do it with echo, put I find printf more satisfying:
Will print the filename starting at column 11, and print ERROR at column 35,
with …. in between. If the filename is too large to fit, it will be partially
overwritten.
Or:
If you always have one space after ‘Modifying’, you could try:
This requires all of the output to available, so that the maximum width can be determined before any data is produced. Since you say “real time”, that is probably not desirable, in which case you could use something like:
To print “….” that is 33 columns wide (adjust as desired). If any file name is too long, that row will be too wide, but there’s really no way to determine the maximum width required unless you wait for all of the data to be available. (Unless you have access to all the file names before you start. Pick a suitable width.) The extra
"..."is there to have at least some dots printed on wide rows, rather than concatenating the file name with the message.