Using Perl:
perl -pi.bak -e 's/(\:50K).+?(\:53B)/${1}CREDIT${2}/g;' input_file
Basic usage:
s/replace_this/with_this/g;
(\:50K)
and (\:53B)
in replace this
part are in parenthesis because these are so called capturing groups. You can refer to these capturing groups as ${1}
and ${2}
(or \1
and \2
) in the with_this
part, CREDIT
as literal replacing whatever is in between ( .+?(\:53B)
- means whatever character, whatever number of occurrences until :53B appears).
:
is escaped because it's a metacharacter in regex.
Backup of the file will be saved to input_file.bak
Using your input, the output is:
$ cat input_file
{:32tyfddf:65 trfdfd :67 ghfdfd :50KCREDIT:53B:fg :43:fg $
{:32tyfddf:65 trfdfd :67 ghfdfd :50KCREDIT:53B:fg :43:fg $
{:32tyfddf:65 trfdfd :67 ghfdfd :50KCREDIT:53B:fg :43:fg $
Hope it helps.