如何替换每个字段中的值直到每条记录中的某个字符?

如何替换每个字段中的值直到每条记录中的某个字符?

每条记录都带有列名称。我必须在每条记录中替换它们,如下所示:

TIME=20181219110000275|CHAN=FMBKHJBAAAADPCFNAAAAAABA|EVNT=SWIgrld|API=SWIrecGrammarActivate|TYPE=uri/2.0|URI=http://media-elr/en-us/grammar/PRVS05/PRVS_param_gram.grxml?SWI.appsessionid=00053050771545238465&SWI.appstepid=1|WGHT=1|PROPS=inet.timeoutDownload=5000;inet.timeoutIO=5000;inet.timeoutOpen=5000;inet.urlBase=http://vxml3-elr:7000/CVP/;swirec_language=en-US|FETCHES=0|MEMHITS=1|MEMMISS=0|DISKHITS=0|DISKMISS=0|LDCPU=0|LDTIME=1|GCCPU=0|GCTIME=0|IFCPU=0|IFTIME=0|IFBYTES=0|COMPILES=0|RC=0|UCPU=186093|SCPU=30828

输出应如下所示:

20181219110000275|FMBKHJBAAAADPCFNAAAAAABA|SWIgrld|SWIrecGrammarActivate|uri/2.0|http://media-elr/en-us/grammar/PRVS05/PRVS_param_gram.grxml?SWI.appsessionid=00053050771545238465&SWI.appstepid=1|1|inet.timeoutDownload=5000;inet.timeoutIO=5000;inet.timeoutOpen=5000;inet.urlBase=http://vxml3-elr:7000/CVP/;swirec_language=en-US|0|1|0|0|0|0|1|0|0|0|0|0|0|0|186093|30828

答案1

  string='abc=something|efgh=anotherThing|klmnop=yet_another_thing'
  string='|'$string    #to prepend with '|' and have a pattern
  result=$( echo "$string" | sed 's/|[a-zA-Z]*=/|/g' )
  result=${result:1}   # remove the leading '|' we added

  something|anotherThing|yet_another_thing

相关内容