`
sharp-fcc
  • 浏览: 105435 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

awk and hadoop之mapper

阅读更多

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 sed

    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 and sed 3

    最新版本的awk和sed,个人感觉挺好的,大家可以下载看看

    awk and sek 2nd

    OReilly.Sed.And.Awk.2nd.Edition.pdf

    awk and sed修订完美高清第三版

    awk and sed修订完美高清第三版,awk与sed这2个工具得确不错

    Awk入门教程 《Awk A Tutorial and Introduction - by Bruce Barnett》

    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 英文版

    awk tutorial and introduction 英文版 网上的连接 http://www.askapache.com/linux/awk-tutorial.html

    sed_awk.chm

    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学习awk学习awk学习awk学习awk学习

    sed and awk 101 hacks

    sed & awk 101 hacks 是sed和awk入门和提高的文档。

    sed and awk 101 hacks.pdf

    免积分下载。

    awk入门到精通.pdf

    (awk 指令并不多, 且其中之大部分与 C语言中之用法一致, 本手册中对该类指令之语法及特性 不再加以繁冗的说明, 读者若欲深究,可自行翻阅相关的 C 语言书籍) 2. awk概述 为什么使用awk awk 是一种程序语言. 它具有...

    Effective awk Programming

    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用法AWK用法AWK用法

    awk ‘/101/’ file 显示文件file中包含101的匹配行。 awk ‘/101/,/105/’ file awk ‘$1 == 5′ file awk ‘$1 == “CT”‘ file 注意必须带双引号 awk ‘$1 * $2 &gt;100 ‘ file awk ‘$2 &gt;5 && $2&lt;=15' file

    sed and awk文档合集

    说是sed和awk的合集,但是里面也有很多其它的东西.其中就包括了一个windows版的grep.本来也有windows的sed,不过好像不好用.呵呵.希望大家捧场. 里面有很多不错的例子.懒得看文档的人有福了阿.

    学习和理解AWK的最佳书籍Effective AWK Programming

    学习和理解AWK的最佳书籍  一致这本书是学习awk的最好书籍,网上下不到的,国内也买不到。国家图书馆和北京大学图书馆都有。强烈建议所有想学awk的同志们阅读(会有很多awk语言之外的启迪) 偶然机会得到,不敢独享...

    Sed and Awk 单行脚本快速参考

    Sed and Awk 单行脚本快速处理字符或者文本

    awk and sed 中文版

    注意是“第3版”rhel饭醉集团出品 国内牛人适当改编第2版 仅供学习。

    awk.Effective.awk.Programming.Universal.Text.Processing.and.Pattern.Matching.4th

    awk.Effective.awk.Programming.Universal.Text.Processing.and.Pattern.Matching.4th

Global site tag (gtag.js) - Google Analytics