gpt4 book ai didi

linux - 找到模式时将行转为列

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:23:00 24 4
gpt4 key购买 nike

这是我要处理的示例文件。我想使用关键字“描述”作为某种 RS,但不知道该怎么做,而且它也不一致。

背景:我正在处理一个日志文件,其中第一行包含日期/时间戳 (APR12),第二行有关于日志的描述。此描述适用于少数日志和 missig。

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.

关于linux - 找到模式时将行转为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30030503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com