- 論壇徽章:
- 0
|
回復(fù) 1# 英語盲學(xué)linux
我看manua時(shí)候,是說每當(dāng)一個(gè)record讀進(jìn)來的時(shí)候, 根據(jù) FS 把每個(gè) $1, $2...$NF 的值確定, 同時(shí)根據(jù)當(dāng)時(shí)OFS也確定了輸出樣式。
只讀取record 或 field 值是不會(huì)對(duì)已經(jīng)確定的東西產(chǎn)生影響,但寫就不一樣了。
如果改變了某一個(gè) field 的值, 比如 $1=$1,(其實(shí)把任何值賦給任何 field 都會(huì)這樣) $1值的改變促使awk重新生成輸出樣式,這時(shí)新的 OFS 就派上用場(chǎng)了。
同時(shí) 改變 $0 的值也是一樣,$0的值改變了,通常來講都會(huì)影響到 field值的改變(只是我用于理解的一種方式,$0=$0就不會(huì)改變$0),所以awk就會(huì)重新生成每個(gè)field的值,這時(shí) FS 便派上用場(chǎng)了。
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.
|
|