ChinaUnix.net
相关文章推荐:

awk 数组

#cat employees Tom Jones 4424 5/12/66 543354 Mary Adams 5346 11/4/63 28765 Sally Chang 1654 7/22/54 650000 Billy Black 1683 9/23/44 336500 #awk '{name[x++]=$2};END{for (i=0;i

by whp5257 - Shell - 2008-03-30 23:42:29 阅读(1866) 回复(7)

相关讨论

我有一个文本内容如下, 330#2.5#2.3 334#12.4#12.0 123#1.5#0.0 330#3.6#2.5 304#34.80#30.60 304#55.55#34.45 330#99.00#55.50 我想做的是如果第n行和 第m行的第1列相等的则分别将m,n行的第2和第3列相加,然后连同第1列输出.否则直接输出;不知道用什么方法,且这个文本有30多万行,我想用awk数组的方法,但是用不好,哪位大哥指点一下.

by bluesky_rhea - Shell - 2005-05-20 14:24:08 阅读(1381) 回复(3)

awk数组一问。 # cat test more test Tom Jones Mary Adams Sally Chang Billy Black Tom Sayage Tom Chung awk '/^Tom/{name[NR]=$1}END{for(i in name){print name}}' test 这是书上的。 感觉很啰嗦,还绕那么大的一个弯子,直接 awk '/^Tom/{name[NR]=$1;print name[NR]}' test 结果是一样的。而且容易理解。

by 小木虫子 - Shell - 2009-07-22 21:37:17 阅读(1289) 回复(7)

awk -F'|' '{++a[$1]} END{for (i in a) print i,a}' aa.tmp awk: cmd. line:1: (FILENAME=aa.tmp FNR=3) fatal: attempt to use array `a' in a scalar context 怎么解决? 谢谢!!

by jack9981 - Shell - 2009-07-03 15:55:28 阅读(1227) 回复(3)

求助,想实现如下统计功能。 有个log,内容类似如下: xxxxxxxx,resp,1001,xxxxxx,56:201,xxxx xxxxxxxx,resp,1001,xxxxxx,56:202,xxxx xxxxxxxx,resp,1001,xxxxxx,56:203,xxxx ...... ...... xxxxxxxx,resp,1002,xxxxxx,56:201,xxxx xxxxxxxx,resp,1002,xxxxxx,56:203,xxxx xxxxxxxx,resp,1002,xxxxxx,56:206,xxxx ...... ...... xxxxxxxx,resp,1007,xxxxxx,56:-13,xxxx xxxxxxxx,resp,1008,xxxxxx,56:9001,xxxx xxxxxxxx,resp,10...

by zjdick - Shell - 2009-06-02 09:42:24 阅读(3773) 回复(11)

xiaobingli:/usr/local/scripts # less data.txt ID Name Age City Country Tel Salary Children 1001 Steven 25 NY U.S.A +01-02-323222 $4900 2 1002 Huang-Yu 30 BJ China +86-10-168888 $6000 1 1003 Fish-Mad 27 SG SG ...

by xiaobing927 - Shell - 2009-03-24 14:39:02 阅读(4418) 回复(7)

[root@test]# cat a.txt 1:2:3 4:5:6 [root@test]# cat b.txt a:b:c d:e:f [root@test]# awk 'BEGIN{OFS=FS=":"} NR==FNR{a[$1]=$2;print a[$1]}' a.txt b.txt 2 5 [root@test]# awk 'BEGIN{OFS=FS=":"} NR>FNR{a[$1]=$2;print a[$1]}' a.txt b.txt b e [root@test]# awk 'BEGIN{OFS=FS=":"} NR==FNR{a[$1]=$2}NR>FNR{$2=a[$1];print}' a.txt b.txt a:5:c d:5:f 疑问:最后NR>FNR{$2=a[$1];print}将a[$1]的值赋给b.txt的$2,然...

by lovegqin - Shell - 2009-01-21 01:16:04 阅读(2606) 回复(18)

awk '{id[$0]=$1};END{print id[1]}' data1.txt 请问这里的$0代表什么啊?谢谢。

by ILoveMK - Shell - 2008-12-11 14:37:46 阅读(1405) 回复(9)

文本内容 ./2006/20060721b/p044559_47.txt ./2006/20060728a/p044559_47.txt ./2007/20070606News/p044559_47.txt ./Olympic City/Shanghai/Cityscape/p044559_47.txt ./2006/20060721b/p053826_01.txt ./Olympic City/Shanghai/Cityscape/p053826_01.txt ./2006/20060719News/Gome/pau52839_02.txt ./2006/20060725a/pau52839_02.txt ./2006/20060726News/TyphoonKeami/pau90550_12.txt ./2006/20060728News/SMS/pau90550_12.txt...

by young1986 - Shell - 2008-11-20 13:20:20 阅读(4236) 回复(17)

3 75 ast 3 33 tmt 2 21 ast awk '{a[$3]+=$1;b[$3]+=$2}END{for(i in a) print a,b,i}' filename 请问a[$3] 和 a[$3]+=$1 表达式 是什么意思? 谢谢

by soccer - Shell - 2008-05-16 22:10:04 阅读(1457) 回复(1)

本帖最后由 wtuter 于 2010-02-05 11:43 编辑 [root@ study]# awk '{ a[NR]=$0;print a[2]}' test linlf man china guangdong linlf man china guangdong linlf man china guangdong linlf man china guangdong [root@ study]# awk '{ a[NR]=$0;print a[1]}' test name sex address name sex address name sex address name sex add...

by wtuter - Shell - 2010-02-03 13:54:41 阅读(10192) 回复(10)