当你在长线上做尾巴时,就会发生包裹。但是,当您跟踪日志时,重要的是要查看一行的结束位置和另一行的开始位置。那么,是否可以在 tail 中创建一个标识?换行不是从第 0 列开始,而是从第 10 列开始。例如:
this is a very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.
this is another very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.
与
this is a very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.
this is another very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.
请注意,我并不是试图修改该行保存到日志文件的方式,而是只是使用不同的格式显示该行。
只需通过管道将尾部连接到您选择的格式化程序即可。一个简单的 Perl 脚本应该可以工作:
tail log-file | perl -pe 's/(.{80})/$1\n\t/g'
将使用制表符缩进行。如果你正在做
tail -f
,你可能会想用 : 来最小化缓冲
tail -f log-file | perl -pe '$|=1; s/(.{80})/$1\n\t/g'
如果:
fmt
(Linux)尝试,例如:
tail -f log | fmt -t
-w
;例如:-w 80
fmt
不会在单词中间分裂,这有助于可读性。但不幸的是,如果没有空格或制表符,它根本不会拆分。