这是我要处理的样本文件。我想用关键字“description”作为某种rs,但不知道怎么做,也不一致。
背景:我正在处理一个日志文件,其中第一行包含日期/时间戳(apr12),第二行包含关于日志的描述。此描述仅适用于少数日志和少数任务。

001 APR12 aaa bbb
Description: This is a test file.
002 APR12 aaa bbb
Description: This is another test file.
003 APR12 aaa XXX
004 APR12 aaa bbb
Description: This is another,after skipping one.

期望输出:
001 APR12 aaa bbb Description: This is a test file.
002 APR12 aaa bbb Description: This is another test file.
003 APR12 aaa XXX
004 APR12 aaa bbb Description: This is another,after skipping one.

最佳答案

$ awk '{printf "%s%s", (/^[0-9]/?rs:FS), $0; rs=RS} END{print ""}' file
001 APR12 aaa bbb Description: This is a test file.
002 APR12 aaa bbb Description: This is another test file.
003 APR12 aaa XXX
004 APR12 aaa bbb Description: This is another,after skipping one.

10-06 06:03