Let's do a simple example. This is what the standard output was printed on screen by Terminal.
Mac:~ usr$ brew list
gdbm libidn2 node python@2 wget
gettext libunistring openssl readline xz
icu4c lz4 python sqlite
However, when I redirect the standard output to a file, the column style is lost.
Mac:~ usr$ brew list | tee "$(date '+%Y-%m-%d-%H%M%S').log"
gdbm
gettext
icu4c
libidn2
libunistring
lz4
node
openssl
python
python@2
readline
sqlite
wget
xz
How can I preserve the standard output style in the output file exactly the same as shown on Terminal screen so that the log file looks pretty?
The log file is not further piped into any other program, function or loop for analysis, where outputting every element every line can be advantageous.
The log file is just for personal reference so I wish to keep it in a reader friendly format, something like IETF's 72 character width. Another purpose for seeking this fashion is that it takes less vertical space when I physically print the file out on a sheet of paper, and perhaps, I can also apply this on other occasions.
Assume Terminal has the default macOS Window Size: 80 Columns x 24 Rows.
Update:
As suggsted by this discussion, I can achieve the desired output by using script
script -q /dev/null brew list | perl -pe 's/\r\n/\n/g' > "$(date '+%Y-%m-%d-%H%M%S').log"
The output style will be preserved but use emacs or vim to open the log file. If I use BBEdit to open the log file, tab width will be visually adjusted --- which led to me to falsely think the command is not working.