我需要将 0 放在我的 grep 的结果上,这样我的脚本格式就可以了,我不知道该怎么做。这是我的 grep 结果:
261 : 261 = 0 | 1192 : 1184 = 8 |
283 : 283 = 0 | 666 : 659 = 7 |
267 : 267 = 0 | 631 : 620 = 11 |
283 : 283 = 0 | 787 : 781 = 6 |
278 : 279 = -1 | 963 : 957 = 6 |
Run Code Online (Sandbox Code Playgroud)
我希望输出这样的东西:
261 : 261 = 000 | 1192 : 1184 = 0008 |
283 : 283 = 000 | 0666 : 0659 = 0007 |
267 : 267 = 000 | 0631 : 0620 = 0011 |
283 : 283 = 000 | 0787 : 0781 = 0006 |
278 : 279 = -001 | 0963 : 0957 = 0006 |
Run Code Online (Sandbox Code Playgroud)
在这里得到这个结果是我的脚本:
count100=`grep -ach "0100 $GivenBIN" $line`
count110=`grep -ach "0110 $GivenBIN" $line`
filename=`echo $line | awk -F"/" '{print $NF}'`
echo -e "$filename $count100 : $count110 = $ans1| $count220 : $count230 = $ans4 |"
Run Code Online (Sandbox Code Playgroud)
根据您的样本输入和输出,我认为
-)。这将转换为以下 awk 脚本,该脚本将printf格式应用于每个数字列。
awk 'BEGIN {
widths[1]=widths[3]=3;
widths[5]=" 4";
widths[7]=widths[9]=widths[11]=4
}
{
for (i in widths) $i = sprintf("%0" widths[i] "d", $i);
print
}'
Run Code Online (Sandbox Code Playgroud)