user3317927 user3317927 - 1 month ago 5x
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

With sed:

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


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