gpt4 book ai didi

linux - 根据unix中的模式将单行拆分为多行

转载 作者:太空宇宙 更新时间:2023-11-04 05:58:37 25 4
gpt4 key购买 nike

我在单行中有以下数据。

输入

pid:1230 received at date 12/1/15 17:00:00:230,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya,pid:1230 sent message at date 12/1/15 17:00:00:232,message ID:1200,name1:anil,name3:kumar,name4:nitin,name5:Rajat,name6:Yogesh,name7:Kishore,name8:satya,pid:1230 Received message at date 12/1/15 17:00:00:232,message ID:1200,nkd1:anil,nkd3:kumar,nkd4:nitin,nkd5:Rajat,nkd6:Yogesh,nkd7:Kishore,nkd8:satya,pid:1230 sent at date 12/1/15 17:00:00:232,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya,pid:1230 received at date 12/1/15 17:00:00:230,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya,pid:1230 sent message at date 12/1/15 17:00:00:232,message ID:1200,name1:anil,name3:kumar,name4:nitin,name5:Rajat,name6:Yogesh,name7:Kishore,name8:satya,pid:1230 Received message at date 12/1/15 17:00:00:232,message ID:1200,nkd1:anil,nkd3:kumar,nkd4:nitin,nkd5:Rajat,nkd6:Yogesh,nkd7:Kishore,nkd8:satya,pid:1230 sent at date 12/1/15 17:00:00:232,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya

我想将单行分成多行。如果该字段包含“收到于”,那么我想拆分为换行符。上面的单行可以分成两行。

预期输出:

pid:1230 received at date 12/1/15 17:00:00:230,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya,pid:1230 sent message at date 12/1/15 17:00:00:232,message ID:1200,name1:anil,name3:kumar,name4:nitin,name5:Rajat,name6:Yogesh,name7:Kishore,name8:satya,pid:1230 Received message at date 12/1/15 17:00:00:232,message ID:1200,nkd1:anil,nkd3:kumar,nkd4:nitin,nkd5:Rajat,nkd6:Yogesh,nkd7:Kishore,nkd8:satya,pid:1230 sent at date 12/1/15 17:00:00:232,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya
pid:1230 received at date 12/1/15 17:00:00:230,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya,pid:1230 sent message at date 12/1/15 17:00:00:232,message ID:1200,name1:anil,name3:kumar,name4:nitin,name5:Rajat,name6:Yogesh,name7:Kishore,name8:satya,pid:1230 Received message at date 12/1/15 17:00:00:232,message ID:1200,nkd1:anil,nkd3:kumar,nkd4:nitin,nkd5:Rajat,nkd6:Yogesh,nkd7:Kishore,nkd8:satya,pid:1230 sent at date 12/1/15 17:00:00:232,message ID:1200,Field1:anil,Field3:kumar,Field4:nitin,Field5:Rajat,Field6:Yogesh,Field7:Kishore,Field8:satya

你能帮我一下吗?谢谢。

最佳答案

您可以尝试这个sed:

sed 's/,\(pid:[0-9]* received at\)/\n\1/g' yourfile

关于linux - 根据unix中的模式将单行拆分为多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311509/

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