user3317927 user3317927 - 3 months ago 7
Bash Question

replace string with its own substring bash

I have string of type

.. 23 { ..


I want to the result should look like

.. { "No":"23" ..


I need to do this in Bash Script. Please help. Thanks in advance.

Need a solution with replaces all occurrences of DD { with {"No":"DD". 'D' is digit

sat sat
Answer

With sed:

sed 's/\(23\)\s*{/{"No":"\1"/g' file

Update:

sed 's/\([0-9]\+\)\s*{/{"No":"\1"/g' file