日志数据示例:
SVCELPTIME=19,FAILPT=9580-8582,MICROSERVICE=YES
SVCELPTIME=411,FAILPT=9210-80129210-8686,MICROSERVICE=YES
REFNO=JAJRJZ,TXNREFNO=63165718100281723,SVCELPTIME=21,FAILPT=9210-80129210-86519210-8651,CD=PT
AFAILPT
被定义为“4位-4位”。例如9580-8582
。我遇到的问题是在某些行上,多个FAILPT
' 被截断为第一行。例如:9580-85819580-85829580-8583
,我需要将它们分别视为一个单独的键值对。
使用 sed:
echo FAILPT=9210-80129210-86519230-8012 | sed 's/FAILPT=//; s/.\{4\}\|.\{4\}-.\{4\}/FAILPT=&,/g; s/,$//'
这会产生:
FAILPT=9210-8012,FAILPT=9210-8651,FAILPT=9230-8012
<-正是我需要的。
但是当我尝试应用日志文件时,它破坏了一切。
例如(使用示例行):
FAILPT=SVCE,FAILPT=LPTI,FAILPT=ME=1,FAILPT=9,95,FAILPT=80-8,FAILPT=582,,FAILPT=MICR,FAILPT=OSER,FAILPT=VICE,FAILPT==YES
FAILPT=SVCE,FAILPT=LPTI,FAILPT=ME=4,FAILPT=11,9,FAILPT=210-,FAILPT=8012,FAILPT=9210-8686,FAILPT=,MIC,FAILPT=ROSE,FAILPT=RVIC,FAILPT=E=YE,S
FAILPT=REFN,FAILPT=O=JA,FAILPT=JRJZ,FAILPT=,TXN,FAILPT=REFN,FAILPT=O=63,FAILPT=1657,FAILPT=1810,FAILPT=0281,FAILPT=723,,FAILPT=SVCE,FAILPT=LPTI,FAILPT=ME=2,FAILPT=1,92,FAILPT=10-8,FAILPT=0129,FAILPT=210-,FAILPT=8651,FAILPT=9210-8651,FAILPT=,CD=,PT
如何仅替换/附加值FAILPT=
而不触及该行的其余部分?
答案1
我用评论回答了我自己的问题。我只需要寻找 4-4 个模式或其中的多个模式。是 OR 子句把事情搞砸了。
sed '/FAILPT=*,/p; s/FAILPT=//; s/.\{4\}-.\{4\}/FAILPT=&,/g; s/,,/,/'