Friday, 11 January 2019
Lines and Word Count of a Given File using Scala
package com.spark.scala.learning
import scala.io.Source
object LinesWordsCount {
def main(args: Array[String]): Unit = {
var file = Source.fromFile("D:\\iEd\\sample.txt")
var countL = 0
for (i <- 0 to file.getLines().length - 1) {
countL = countL + 1
}
file.close()
file = Source.fromFile("D:\\iEd\\sample.txt")
var countW = 0
for (j <- file.getLines()) {
countW = countW + j.split("").size
}
println("The Number of Lines : " + countL)
println("The Number of words : " + countW)
}
}
The Number of Lines : 4
The Number of words : 91
Subscribe to:
Post Comments (Atom)
Flume - Simple Demo
// create a folder in hdfs : $ hdfs dfs -mkdir /user/flumeExa // Create a shell script which generates : Hadoop in real world <n>...
-
Input file: emp.csv ---------------- empno,ename,designation,manager,hire_date,sal,deptno 7788,SCOTT,ANALYST,7566,12/9/1982,3000,20 73...
-
<!-- https://mvnrepository.com/artifact/org.mongodb.spark/mongo-spark-connector --> <dependency> <groupId>org.mong...
-
External table creation in Hive $ cat > sample_1.csv 18282782,NW 1929SEGH2,BSTN 172u8562,PLA 121232,JHK 3443453,AG $ hdfs dfs -...
No comments:
Post a Comment