- 一.官方 Grep 案例
- 二.官方 WordCount 案例
从一堆配置文件中匹配出开头以dfs开头的单词
- 创建在hadoop-2.7.2文件下面创建一个input文件夹
[atguigu@hadoop101hadoop-2.7.2]$ mkdir input
- 将Hadoop的xml配置文件复制到input
[atguigu@hadoop101hadoop-2.7.2]$ cp etc/hadoop/*.xml input
- 执行share目录下的MapReduce程序
[atguigu@hadoop101hadoop-2.7.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input output 'dfs[a-z.]+'
- 查看输出结果
[atguigu@hadoop101hadoop-2.7.2]$ cat output/part-r-00000 1 dfsadmin
从一个文件中统计一下每个单词的次数
- 创建在hadoop-2.7.2文件下面创建一个wcinput文件夹
[atguigu@hadoop101hadoop-2.7.2]$ mkdir wcinput
- 在wcinput文件下创建一个wc.input文件
[atguigu@hadoop101hadoop-2.7.2]$ cd wcinput [atguigu@hadoop101wcinput]$ touch wc.input
- 编辑wc.input文件
[atguigu@hadoop101wcinput]$ vi wc.input 在文件中输入如下内容: hadoop yarn hadoop mapreduce atguigu atguigu 保存退出::wq
- 回到Hadoop目录/opt/module/hadoop-2.7.2
- 执行程序
[atguigu@hadoop101hadoop-2.7.2]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount wcinput wcoutput
- 查看结果
[atguigu@hadoop101hadoop-2.7.2]$ cat wcoutput/part-r-00000 atguigu 2 hadoop 2 mapreduce 1 yarn 1



