我有两个文件。 我正在search的输出文件有地震位置,格式如下:
19090212 1323 30.12 36 19.41 103 28.24 7.29 0.00 4 149 25.8 0.02 5.7 9.8 D - 0 19090216 1828 49.61 36 13.27 101 35.38 10.94 0.00 13 54 38.5 0.07 0.3 0.7 B 0 19090711 2114 54.11 35 1.07 99 56.42 7.00 0.00 7 177 18.7 4.00 63.3 53.2 D # 0
我想使用第一列的前6位(即“19090418”中的'090418')和第二列的前3位(即'0728'中的'072')作为search项。 我正在search的文件具有以下格式:
SC17 P 090212132329.89 X25A P 090212132330.50 AMTX P 090216182814.12 X29A P 090216182813.70 Y28A P 090216182822.36 MSTX P 090216182826.80 Y27A P 090216182831.43
在search第二个文件后,我需要确定该部分有多less行。 所以对于这个例子,如果我正在search上面第二个文件中显示的术语,我想知道090212132有2行,090216182有5行。
这是我的第一篇文章,所以请让我知道我可以如何提高我的post的清晰度或简洁性。 谢谢您的帮助!
如何使用schell脚本从文件读取元素,做一些计算和回写?
用最后一个已知列(sed / awk / script)replace空/空列
Unix Awk数组不打印值
AWK。 循环遍历目录并求和列
将区块中的行转换为制表符分隔
在bash中将可读的人转换为字节
计算基于时间的指标(每小时)
Gawk打印每列最大的值
在Hortonworks分发中归档HDFS文件时的AWK使用问题
awk来拯救!
$ awk 'NR==FNR{a[substr($1,3) substr($2,1,3)]; next} {k=substr($3,9)} k in a{a[k]++} END{for(k in a) if(a[k]>0) print k,a[k]}' file1 file2
100224194 7 100117172 18 091004005 11 090520220 10 090526143 21 090122033 20
谢谢您的帮助!
卡拉夫卡回答与解释
awk 'NR==FNR { # For first file $1 = substr($1,3); # Get last 6 characters from first col $2 = substr($2,3); # Get first 3 characters from second col a[$1 $2]; # Add to an array next } # Move to next record in first file # Start processing second file {k = substr($3,9)} # Get first 9 character for third col k in a {a[k]++} # If key in a,then increment the key END { for (k in a) # Iterate array if (a[k] > 0) # If pattern was matched print k,a[k] # print the pattern and num occurrence }'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。