gpt4 book ai didi

linux - AWK/SED 附加到日志文件

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

我有一个运行的 qpid 命令,它给了我一个漂亮的 mat 打印,如下所示:

{
"value": {
"application": {
"connectionState": "Disconnected",
"connectionTime": "No connection was established",
"linkAttributes": {
"ackSettings": {
"dataAckEnabled": "true",
"dataAckTimeout": "5000",
"dataNakRetryLimit": "0",
"retransmitDelay": "500"
},
"keepAliveSettings": {
"keepAliveAckTimeout": "5000",
"keepAliveInterval": "30000"
},
"logTraffic": "false",
"port": "9999",
"role": "server"
},
"protocol": "Class"
}
},
"queueStats": {}

我获取此输出并去掉退出标记和括号,然后使用以下命令将其附加到日志文件:

command | sed 's/"//g'  | sed 's/{//g' | sed 's/}//g' | sed -e 's/$/\r/g' |awk '!/""/{ORS=(/},/?RS:""); gsub(/[[:blank:]]+/,""); sub(/}$/,"},\n"); print}' |awk '{gsub(/\\n/,"\n")}1' >> app.log

结果如下:

  ^M^M^MendpointApplications:^MApplicationSide:^MconnectionState:Disconnected,^MconnectionTime:Noconnectionwasestablished,^MlinkAttributes:^MackSettings:^MdataAckEnabled:true,^MdataAckTimeout:5000,^MdataNakRetryLimit:0,^MretransmitDelay:500^M,^MkeepAliveSettings:^MkeepAliveAckTimeout:5000,^MkeepAliveInterval:30000^M,^MlogTraffic:false,^Mport:9999,^Mrole:server^M,^Mprotocol:ClassD^M^M,^MqueueStats:^M

每次我想将输出附加到日志的新行中时,如何去掉 ^M 字符?

我的预期结果是:

    endpointApplications:ApplicationSide:connectionState:Disconnected,connectionTime:Noconnectionwasestablished,linkAttributes:ackSettings:dataAckEnabled:true,dataAckTimeout:5000,dataNakRetryLimit:0,retransmitDelay:500,keepAliveSettings:keepAliveAckTimeout:5000,keepAliveInterval:30000,logTraffic:false,port:9999,role:server,protocol:ClassD,queueStats:

基本上,结果与以前相同,但没有 ^M 字符,我想每次将命令的结果附加到新的石灰上。

最佳答案

您的 sed 命令 s/$/\r/ 正在注入(inject)它们。只是不要这样做!

关于linux - AWK/SED 附加到日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39518219/

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