0

得到一个日志,看起来像这样:

2012-02-10 11:00:44.211 connection closed_to host
2012-02-10 11:00:44.598 connection closed_to host
2012-02-10 11:00:45.510 connection closed_to host
2012-02-10 11:00:45.891 connection closed_to host
2012-02-10 11:00:46.111 connection closed_to host

有人可以帮助我,我怎么能做这样的输出(使用awk)?

connection closed_to host
11:00:44.211

connection closed_to host
11:00:44.598
4

3 回答 3

1

您可以使用以下命令:

awk '{for(i=3;i<=NF;i++){printf "%s ",$i}; printf "\n"$2"\n\n" }' log

awk将逐行解析文件。

对于每一行,awk

  1. 打印从第三个到最后一个参数
  2. 打印第二个参数
于 2013-05-15T15:12:12.887 回答
1

与外壳:

while read date time msg; do echo "$msg"; echo $time; echo; done < log
于 2013-05-15T16:07:32.913 回答
0

简单地:

$ awk '{print $3,$4,$5"\n"$2"\n"}' log
connection closed_to host
11:00:44.211

connection closed_to host
11:00:44.598

connection closed_to host
11:00:45.510

connection closed_to host
11:00:45.891

connection closed_to host
11:00:46.111
于 2013-05-15T15:59:21.357 回答