我正在将 Macos 与此版本的 Bash 一起使用:
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)
我正在 grep 一个日志文件并将结果通过管道传输到
cut
,我试图删除每行的前 64 个字符。
这有效(无需剪切):
$ tail -f log/development.log | grep mailer
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/part_container.rb:45:in `parse_content_type': content_type = "xls"
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/part.rb:60:in `to_mail': real_content_type = "xls"; ctype_attrs = {"charset"=>"utf-8"}
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb:793:in `set_content_type': str = "xls"; sub = nil; param = {"name"=>"pmll_print_publisher_summary.xls"}
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/part_container.rb:45:in `parse_content_type': content_type = "multipart/alternative"
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/part_container.rb:45:in `parse_content_type': content_type = "xls"
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/part.rb:60:in `to_mail': real_content_type = "xls"; ctype_attrs = {"charset"=>"utf-8"}
### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb:793:in `set_content_type': str = "xls"; sub = nil; param = {"name"=>"pmll_print_publisher_summary.xls"}
我想删除每行的前 64 个字符(“### /Users/max/.asdf/installs/ruby/1.8.7/lib/ruby/gems/1.8/gems/”)。 我想如果我像这样将结果通过管道传输到
cut
就会起作用。 但我什么也没得到。
$ tail -f log/development.log | grep mailer | cut -c 64-
编辑:一些评论者认为这是一个缓冲问题。 我尝试过以下方法来解决这个问题:
$ tail -f log/development.log | unbuffer grep mailer | cut -c 65-
-bash: unbuffer: command not found
$ tail -f log/development.log | stdbuf -oL grep mailer | cut -c 65-
<blank, as above>
$ tail -f log/development.log | stdbuf -o0 grep mailer | cut -c 65-
<blank, as above>
$ tail -f log/development.log | grep --line-buffered mailer | cut -c 65-
<blank, as above>
在我的 Debian/XFCE/xterm 窗口上,我运行:
tail -f log/development.log | grep --line-buffered mailer | cut -c 65-
在另一个 xterm 窗口上,我运行:
echo "/actionmailer-2.2.2/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb" >> log/development.log
每个
echo
都会在第一个窗口中立即生成nterface.rb
。