You can use zipWithIndex() to get index for each record and then you can increment by 1 for each index.
val tf=sc.textFile("test").zipWithIndex() tf.map(s=>(s[1]+1,s[0])) Above should serve your purpose. -- View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/When-do-map-how-to-get-the-line-number-tp22318p22334.html Sent from the Apache Spark User List mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@spark.apache.org For additional commands, e-mail: user-h...@spark.apache.org