准备一个文件上传至hdfs
hello word
hello java
hello python
hello c++
启动spark-shell
spark-shell
获取到要计算的文件
val file = spark.read.textFile("test.txt")
统计该文件的行数
file.count()
获取第一行的内容
file.first()
获取到特定的内容
val lines = file.filter(line => line.contains("hello"))
获取指定词出现的次数
file.filter(line => line.contains("hello")).count()