import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DistributedFileSystem; /** * * @author Shashwat Shriparv * @email dwivedishashwat@gmail.com * @web helpmetocode.blogspot.com */ public class RecursivelyPrintFilesOnHDFS { public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException { printFilesRecursively("hdfs://master1:9000/"); } public static void printFilesRecursively(String Url) throws IOException { try {
All the question that scared me now i am trying to scare them .. so that they cant scare others :)
Saturday, April 13, 2013
List Files from hdfs/Hadoop Recursively using java
Write file to HDFS/Hadoop Read File From HDFS/Hadoop Using Java
import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DistributedFileSystem; /** * * @author Shashwat Shriparv * @email dwivedishashwat@gmail.com * @Web helpmetocode.blogspot.com */ public class WritetoHDFSReadFromHDFSWritToLocal { private static byte[] buffer; private static int bytesRead; public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException {
Thursday, April 4, 2013
Insert string after each N lines in a file
We can do this as follows:
awk '1;!(NR%<Number after which the line has to be insserted>){print "String to be inserted";}' origionalfiletoprocess >outfilewithinsertedstring
Eg:
awk '1;!(NR%100){print "Shashwat Shriparv";}' filecontainingtxt>outputfilewithnewinsertedlines
This command will read filecontainingtxt and will insert string Shashwat Shriparv after 100 lines the the output fill will be outputfilewithnewinsertedlines
Tuesday, April 2, 2013
Subscribe to:
Posts (Atom)
Featured Posts
🎬 Installing Kali Linux on a Virtual Machine | Step-by-Step Guide 🐧
🎬 In this video, I’ll show you how to install Kali Linux 🐧 inside a Virtual Machine step-by-step! Whether you're a beginner curious...

-
Configuration config = HBaseConfiguration.create(); Job job = new Job(config,"ExampleReadWrite"); job.setJarByClass(MyReadWriteJo...
-
Use the following function which is built in percentile(BIGINT col, p) and set p to be 0.5 and will calculate the median credit : ...