- 论坛徽章:
- 0
|
回复 1# 英语盲学linux
我看manua时候,是说每当一个record读进来的时候, 根据 FS 把每个 $1, $2...$NF 的值确定, 同时根据当时OFS也确定了输出样式。
只读取record 或 field 值是不会对已经确定的东西产生影响,但写就不一样了。
如果改变了某一个 field 的值, 比如 $1=$1,(其实把任何值赋给任何 field 都会这样) $1值的改变促使awk重新生成输出样式,这时新的 OFS 就派上用场了。
同时 改变 $0 的值也是一样,$0的值改变了,通常来讲都会影响到 field值的改变(只是我用于理解的一种方式,$0=$0就不会改变$0),所以awk就会重新生成每个field的值,这时 FS 便派上用场了。
It is a not-uncommon error to try to change the field separators in a record simply by setting FS and OFS, and then expecting a plain ‘print’ or ‘print $0’ to print the modified record.
But this does not work, since nothing was done to change the record itself. Instead, you must force the record to be rebuilt, typically with a statement such as ‘$1 = $1’, as described earlier.
|
|