<p>有了<code>awk</code>,您可以试着用GNU<code>awk</code>中显示的样本编写并测试以下内容吗</p>
<p>如果不使用字段分隔符,请尝试:</p>
<pre><code>awk 'substr($0,5,1)==0{ $0=substr($0,1,4) substr($0,6) } 1' Input_file
</code></pre>
<p>或者使用字段分隔符尝试以下操作:在这里只处理第一个字段</p>
<pre><code>awk '
BEGIN{
FS=OFS=":"
}
substr($1,5,1)==0{
$1=substr($1,1,4) substr($1,6)
}
1
' Input_file
</code></pre>
<p>若要将输出保存到输入_文件本身,请在对上述命令的输出满意后附加<code> > temp && mv temp Input_file</code></p>
<p><em><strong>解释:</strong></em>添加上述内容的详细解释</p>
<pre><code>awk ' ##Starting awk program from here.
BEGIN{ ##Starting BEGIN section of this program from here.
FS=OFS=":" ##Setting FS and OFS as colon here.
}
substr($1,5,1)==0{ ##Checking condition if 5th character is 0 then do following.
$1=substr($1,1,4) substr($1,6) ##Setting sub string of 1st 4 characters then mentioning characters from 6th character to last of 1st field here.
}
1 ##1 will print current line.
' Input_file ##Mentioning Input_file name here.
</code></pre>