1. 在awk 中mapper的时候我们经常会合并不同的文件,取我们想要的不同的字段。
awk -F "\t" ' { filename = ENVIRON["mapreduce_map_input_file"]; if (index(filename, "xxxx") > 0) { // xxx } else { //xxxx } }
这样来取文件的名字,来判断当前处理的行属于哪个文件,以此进行相应的处理。
2. 在hadoop 中我们经常需要对两个文件做一个join操作,即取两个文件的交集,或者在一个集合中过滤掉特定的集合,如果这个一个集合很小, 我们可以把这个集合加入到一个字典中,然后过滤, 在mapper 中这么写。
awk -F "\t" -v file=${smail_set} ' BEGIN{ while (getline < file > 0) { dict[$1] = 1; } } { if($1 in dict) //xxxx else print xxxx } '
reducer 直接 uniq 即可
3. 如果两个集合做 join 或者补集的操作,那么只能对集合打标签,在mapper中我们这么写:
awk -F "\t" ' { filename = ENVIRON["mapreduce_map_input_file"]; if (index(filename, "xxxx") > 0) { print $1"\t0\t"$0 } else { print $1"\t1\t"$0 } }
第二列 一个0 一个1 用$1 让他们combine的时候到一起去,结合shuffle时候的二次排序,可以搞定
相关推荐
awk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sedawk and sed
最新版本的awk和sed,个人感觉挺好的,大家可以下载看看
OReilly.Sed.And.Awk.2nd.Edition.pdf
awk and sed修订完美高清第三版,awk与sed这2个工具得确不错
Awk入门教程。作者 Bruce Barnett 注:英文版。以下是目录 Why learn AWK? Basic Structure Executing an AWK script Which shell to use with AWK? Dynamic Variables The Essential Syntax of AWK ...
awk tutorial and introduction 英文版 网上的连接 http://www.askapache.com/linux/awk-tutorial.html
This book is about a set of oddly named UNIX utilities, sed and awk. These utilities have many things in common, including the use of regular expressions for pattern matching. Since pattern matching ...
awk学习awk学习awk学习awk学习awk学习awk学习awk学习
sed & awk 101 hacks 是sed和awk入门和提高的文档。
免积分下载。
(awk 指令并不多, 且其中之大部分与 C语言中之用法一致, 本手册中对该类指令之语法及特性 不再加以繁冗的说明, 读者若欲深究,可自行翻阅相关的 C 语言书籍) 2. awk概述 为什么使用awk awk 是一种程序语言. 它具有...
The focus is on the practical side of creating and running awk scripts, and there's plenty of hands-on advice for installing and running today's awk (and gawk)., The book begins with the fundamentals...
awk ‘/101/’ file 显示文件file中包含101的匹配行。 awk ‘/101/,/105/’ file awk ‘$1 == 5′ file awk ‘$1 == “CT”‘ file 注意必须带双引号 awk ‘$1 * $2 >100 ‘ file awk ‘$2 >5 && $2<=15' file
说是sed和awk的合集,但是里面也有很多其它的东西.其中就包括了一个windows版的grep.本来也有windows的sed,不过好像不好用.呵呵.希望大家捧场. 里面有很多不错的例子.懒得看文档的人有福了阿.
学习和理解AWK的最佳书籍 一致这本书是学习awk的最好书籍,网上下不到的,国内也买不到。国家图书馆和北京大学图书馆都有。强烈建议所有想学awk的同志们阅读(会有很多awk语言之外的启迪) 偶然机会得到,不敢独享...
Sed and Awk 单行脚本快速处理字符或者文本
注意是“第3版”rhel饭醉集团出品 国内牛人适当改编第2版 仅供学习。
awk.Effective.awk.Programming.Universal.Text.Processing.and.Pattern.Matching.4th