Hadoop——练习1(统计单词个数)
Posted 小镭敲代码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hadoop——练习1(统计单词个数)相关的知识,希望对你有一定的参考价值。
1、启动Hadoop
cd /opt
cd hadoop
./sbin/start-all.sh
jps
2、创建一个txt,存入英文单词
vi blue
i(输入)——>est键(退出)——wq(保存)
3、使用 put 操作将“blue”文件上传到 HDFS 的根目录
hadoop fs -put blue /blue
4、使用 jar 操作运行 Hadoop 中自带的 jar 进行单词计数
cd hadoop/share/hadoop/mapreduce/
hadoop jar hadoop-mapreduce-examples-2.7.1.jar wordcount /blue /out
5、使用 cat 查看统计结果
hadoop fs -cat /out/part-r-00000
*戳爷版BLUE歌词
Love It's hard I know
All your lIghts are red but I'm green to Go
Used to see you hIgh now you're only low
All your lIghts are red but I'm green to Go
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
I can't say no though the lIghts are on
There's nobody home
Swore I'd never lose control
Then I fell in love wIth a heart that beats so slow
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
I know you're seeing black and whIte
So I'll paint you a clear-blue sky
WIthout you I am colour-blind
It's raining every tIme I open my eyes
I know you're seeing black and whIte
So I'll paint you a clear-blue sky
WIthout you I am colour-blind
It's raining every tIme I open my eyes
I want you I'll colour me blue
Only seeing myself
When I'm loOKing up at you
When I'm loOKing up at you
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
When I'm loOKing up at you
I want you I'll colour me blue
Anything It takes to make you stay
Only seeing myself
When I'm loOKing up at you
I want you I'll colour me blue
Anything It takes to make you stay
7、错误:重复上上面的操作,创建一个新的hello.txt,发现不能统计单词数目
解决办法:将out改成out1
结果:
以上是关于Hadoop——练习1(统计单词个数)的主要内容,如果未能解决你的问题,请参考以下文章
统计一段文章的单词频率,取出频率最高的5个单词和个数(python)
Leetcode练习(Python):第434题:字符串中的单词数:统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。 请注意,你可以假定字符串里不包括任何不可打印的字符。
Leetcode练习(Python):第434题:字符串中的单词数:统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。 请注意,你可以假定字符串里不包括任何不可打印的字符。