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
How to Auto-Terminate Frozen and Hung Apps in Windows
We have all been there. You are in the middle of an important project or a gaming session, and suddenly, your screen freezes. The dreaded ...
-
public struct CoOrds { public int x, y; public CoOrds( int p1, int p2) { x = p1; y = p2; } }
-
Manage timer jobs You can check the status of a timer job and edit the timer job definition. For the general administration of ...