- 論壇徽章:
- 8
|
原帖由 ruifox 于 2007-7-23 09:40 發(fā)表 ![]()
這個(gè)問題頗有點(diǎn)古怪,F(xiàn)S的賦值方式明顯不對(duì),但執(zhí)行的結(jié)果也很難理解!
為什么第一行能夠執(zhí)行正確,但第二行數(shù)據(jù)就出現(xiàn)問題,而且似乎還影響了OFS,奇怪!
期待高手!
awk 'FS="\t" gsub(/a/,"A",$1)'執(zhí)行 ...
第一行FS="\t"以前域已經(jīng)拆分好了
第二行行才按\t拆分,結(jié)果是非常相當(dāng)?shù)恼5?br />
- Advanced Notes: Changing FS Does Not Affect the Fields
- According to the POSIX standard, awk is supposed to behave as if each record is split into fields at the time it is read. In particular, this means that if you change the value of FS after a record is read, the value of the fields (i.e., how they were split) should reflect the old value of FS, not the new one.
- However, many implementations of awk do not work this way. Instead, they defer splitting the fields until a field is actually referenced. The fields are split using the current value of FS! (d.c.) This behavior can be difficult to diagnose. The following example illustrates the difference between the two methods. (The sed18 command prints just the first line of /etc/passwd.)
- sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
- which usually prints:
- root
- on an incorrect implementation of awk, while gawk prints something like:
- root:nSijPlPhZZwgE:0:0:Root:/:
復(fù)制代碼 |
|