亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1606 | 回復(fù): 8
打印 上一主題 下一主題

求教 awk 重組問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-04-20 13:33 |只看該作者 |倒序?yàn)g覽
當(dāng)設(shè)定了OFS后 想要使用新的分隔符 一般都會(huì)使用類似 $1=$1,NF+=0

所以想問下 當(dāng)awk 看到$1=$1 他是怎么來判斷的或者說這個(gè)是怎么執(zhí)行的

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報(bào)曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
2 [報(bào)告]
發(fā)表于 2012-04-20 13:39 |只看該作者
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 older 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.

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2012-04-20 13:41 |只看該作者
回復(fù) 2# waker


    你難到?jīng)]看到樓主的名么
還在這粘英文

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報(bào)曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
4 [報(bào)告]
發(fā)表于 2012-04-20 13:44 |只看該作者
dahaoshanhe 發(fā)表于 2012-04-20 13:41
回復(fù) 2# waker


俺也是英語盲,understand?

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2012-04-20 13:46 |只看該作者
回復(fù) 2# waker


    先謝了 不過我真看不懂

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2012-04-20 13:55 |只看該作者
回復(fù) 2# waker


    不過大體意思是如果沒域內(nèi)的值改變了 那么OFS就會(huì)應(yīng)用新的嗎?

論壇徽章:
3
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亞洲杯之阿曼
日期:2015-04-07 20:00:59
7 [報(bào)告]
發(fā)表于 2012-04-20 13:56 |只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2012-04-21 08:52 |只看該作者
回復(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.

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報(bào)曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
9 [報(bào)告]
發(fā)表于 2012-04-21 09:36 |只看該作者
英語盲學(xué)linux 發(fā)表于 2012-04-20 13:55
回復(fù) 2# waker


如果不是特殊需要,一般在BEGIN{}中設(shè)置FS/OFS就不會(huì)有諸多煩惱了
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP