我正在尝试用另一个模式替换固定模式。需要替换的模式是:
{
"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.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",
},
我如何使用sed
命令来实现这一点?
答案1
sed 's/your-long-pattern/&the-additional-text/' inputfile
“&”符号重复找到的字符串。
您可能还可以使用:
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
(未经测试)