user3317927 user3317927 - 1 year ago 74
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 Source

With sed:

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


sed 's/\([0-9]\+\)\s*{/{"No":"\1"/g' file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download