1

Appreciate any help to find out the solution for below scenario.

Input:

:50Kfoobar:53B:53B:53Bbaz:53B:53B;:50Kvoocar:53B:53B:53Bbaz:53B:53B

Output:

:50KCREDIT:53B:53B:53Bbaz:53B:53B;:50KCREDIT:53B:53B:53Bbaz:53B:53B

Tried using below command

sed 's/:50K.*:53B/:50KCREDIT:53B/g' <<<':50Kfoobar:53B:53B:53Bbaz:53B:53B;:50Kvoocar:53B:53B:53Bbaz:53B:53B'

producing below result
:50KCREDIT:53B

anubhava
  • 761,203
  • 64
  • 569
  • 643
Sen
  • 79
  • 5

1 Answers1

3

With your shown samples, please try following.

awk '{gsub(/:50K[^:]*:53B/,":50KCREDIT:53B")} 1' Input_file

Explanation: using regex :50K[^:]*:53B which will match :50K till next occurrence of :(non-greedy match) then matching : followed by 53B, then replacing this matched part with :50KCREDIT:53B globally, finally printing the current line.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93