Hi I am trying to replace a fixed pattern with another pattern. The pattern which got to be replaced is { "field_name": "genDtl.schmNature", "data_type": "tbaFlagType","fld_size": "0","bspc": "", "type": "hardcoded", "value": "N", "neg_value": "", "desc": "", "is_fetch_input": "N", },

and the resulting pattern should be

{ "field_name": "genDtl.schmNature", "data_type": "tbaFlagType","fld_size": "0","bspc": "", "type": "hardcoded", "value": "N", "neg_value": "", "desc": "", "is_fetch_input": "N", }, { "field_name": "genDtl.autoClsOfZeroBalAcctFlg", "data_type": "tbaFlagType","fld_size": "0","bspc": "", "type": "hardcoded", "value": "Y", "neg_value": "", "desc": "", "is_fetch_input": "N", },

link|improve this question
feedback

1 Answer

sed 's/your-long-pattern/&the-additional-text/' inputfile

The ampersand repeats the found string.

You might also be able to use:

sed 's/\({ "field_name": "\)\(genDtl.schmNature\)\(", "data_type": "tbaFlagType","fld_size": "0","bspc": "", "type": "hardcoded", "value": "\)\(N\)\(", "neg_value": "", "desc": "", "is_fetch_input": "N", },\)/\1\2\3\4\5\1genDtl.autoClsOfZeroBalAcctFlg\3Y\5/' inputfile

(untested)

link|improve this answer
For large substitutions like this, I suggest using an external sed script file with the -e flag, e.g. sed -e foo.sed <infile > outfile. Registers are fine or you can apply multiple "s" commands in the sed file to each line. – kmarsh Jul 22 '10 at 17:46
@kmarsh: -e is for an in-line script. I think you mean -f which takes a filename. By "registers" do you mean capture groups/back references? – Dennis Williamson Jul 22 '10 at 20:42
Yes, I meant -f. The term "Registers" can be found in some families of man pages, on GNU systems do "info regex" and search for registers, in section 7.1.8 on my Linux system. – kmarsh Aug 9 '10 at 17:09
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.