【问题标题】:How to format output file at the command line?如何在命令行格式化输出文件?
【发布时间】:2013-02-14 06:34:35
【问题描述】:

我正在使用 grep 检索日志文件时间戳后的所有日志。

grep -A 100 "2013/02/13 19*" log.out > newfile.txt

有没有办法在命令行格式化它,以便文本文件的新行从特定文本开始?例如,我希望“信息”从新行开始。

【问题讨论】:

  • 您将不得不详细说明一下。现在的输出是什么样的?

标签: unix sed awk grep


【解决方案1】:

使用 sed 从 grep 的输出中删除 \r 和 \n 字符,然后使用 sed 将“特定文本”替换为“特定文本\n”字符。我想它应该可以工作。

【讨论】:

  • 我试过 sed -i "s/INFO/INFO\n/g" newfile.txt 但是当我在 Windows 中打开 newfile.txt 时,它看起来仍然没有格式化。
  • 要么使用notepad++,或者如果你想在windows的记事本中看到换行符,使用\r\n而不是仅仅\n
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-15
  • 1970-01-01
  • 2011-09-21
相关资源
最近更新 更多