awk 选择数据行
我必须使用 awk 处理以下数据文件:
YEARS:1995:1996:1997:1998:1999:2000
VISITS
Domain1:259:2549:23695:24889:1240:21202
Domain2:32632:87521:147122:22952:2365:121230
Domain3:5985:92104:921744:43124:74234:68350
Domain4:8321:36520:68712:32102:22003:82100
SIGNUPS
Domain1:212:202:992:1202:986:3253
Domain2:10401:44522:20103:3595:11410:353
Domain3:3695:23230:452030:25052:9858:3020
Domain4:969:24247:9863:24101:5541:3663
我需要知道每年和域的总访问量和注册量。我的问题是我找不到只选择前四行和后四行的方法,任何人都可以给我一些关于如何实现这一目标的提示吗?
输出示例(仅限访问):
VISITS
Domain1 73834
Domain2 413822
Domain3 1205541
Domain4 309758
1995 1996 1997 1998 1999 2000
All 47197 218694 1161273 123067 99842 292882
I have to process the following datafile using awk:
YEARS:1995:1996:1997:1998:1999:2000
VISITS
Domain1:259:2549:23695:24889:1240:21202
Domain2:32632:87521:147122:22952:2365:121230
Domain3:5985:92104:921744:43124:74234:68350
Domain4:8321:36520:68712:32102:22003:82100
SIGNUPS
Domain1:212:202:992:1202:986:3253
Domain2:10401:44522:20103:3595:11410:353
Domain3:3695:23230:452030:25052:9858:3020
Domain4:969:24247:9863:24101:5541:3663
I need to know for each year and domain the total visits and signups. My problem is I can't find a way to select only the first four and the last four rows, can anybody give me some kind of hint on how to achieve that?
Example output (Visits only):
VISITS
Domain1 73834
Domain2 413822
Domain3 1205541
Domain4 309758
1995 1996 1997 1998 1999 2000
All 47197 218694 1161273 123067 99842 292882
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以匹配“VISITS”和“SIGNUPS”行,并设置一个变量来指示您正在处理的记录类型。
一个例子:
You could match the "VISITS" and "SIGNUPS" rows and set a variable indicating what kinds of records you are processing.
An example:
使用 GNU awk 你可以使用:
代替:
With GNU awk you could use:
instead of:
当您说“仅选择前四行和最后四行”时,我假设您的意思是分别处理访问和注册:
根据您的输入,此输出
When you say "select only the first four and the last four rows", I assume you mean to process the visits and signups separately:
Given your input, this outputs