问题描述
我们如何从输入文件下方删除EES
how do we remove EES from below input file
{"last_name":"Kiran","first_name":"kumar","sno":"1234","effective_date":"11/01/2011","cancel_date":"12/31/9999","alt_ein_id_indicator":"Y","alt_ein_id_employer_number":"V3EES"}
期待转换后的文件看起来像这样
Expecting the file after transformation to look like this
{"last_name":"Kiran","first_name":"kumar","sno":"1234","effective_date":"11/01/2011","cancel_date":"12/31/9999","alt_ein_id_indicator":"Y","alt_ein_id_employer_number":"V3"}
TIA
推荐答案
在awk之后,应从第8个字段或第7个冒号后面删除EES字符串.
Following awk should remove the EES string from 8th field or after 7th colon.
awk -F':' '{sub("EES","",$8)} 1' OFS=":" Input_file
很快就会添加详细的解释.
Will add a detailed explanation for same too shortly.
说明:
awk -F':' 表示我在这里设置字段分隔符,默认情况下,awk字段分隔符的值为空格,因此我现在设置为冒号.因此,它将仅在与结肠有关的部分中断开线段.
awk -F':' Means I am setting up field separator here, by default in awk field separator's value is space so I am setting into colon now. So it will break the lines in parts with respect to colon only.
{sub("EES",",$ 8)} 的意思是,我正在使用awk的替代实用程序,它将在方法sub(regex_to_be_subsituted,new_value ,current_line/variable).因此,在这里,我给字符串EES用$ 8中的NULL(")替换表示行的第8个字段(您在第7个冒号之后提到).
{sub("EES","",$8)} Means, I am using substitute utility of awk, which will work on method sub(regex_to_be_subsituted,new_value,current_line/variable). So here I am giving string EES to be substituted with NULL("") in $8 means 8th field of the line(which you mentioned after 7th colon).
1 的意思是,awk在先条件后操作的方法上工作,因此通过写1我将条件设为TRUE,但未提及任何操作,因此默认情况下打印将会发生.
1 means, awk works on method of condition then action, so by writing 1 I am making condition TRUE and didn't mention any action, so by default print will happen.
OFS =:" 的意思是,设置输出字段分隔符,默认情况下OFS将是空格,因此根据您的Input_file,我将其设置为:
OFS=":" Means, setting output field separator, by default OFS will be space so as per your Input_file I am setting it to :
输入文件 的意思是,在这里只需提及输入文件的名称即可.
Input_file Means, simply mentioning Input_file name here.
如果您要将输出保存到相同的Input_file中,那么以下内容可能会对您有所帮助.
If you want to save output into same Input_file then following may help you.
awk -F':' '{sub("EES","",$8)} 1' OFS=":" Input_file > temp_file && mv temp_file Input_file
这篇关于Shell-如何删除字符串"EES"从第7次冒号(:)出现后的记录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!