0

i need to sort a csv file by the first column, which is a timestamp. I've been trying to do this with the following code, but the inputstream of the process p is always just blank:

    Process p = Runtime.getRuntime().exec("sort -k1,1 -t, Bucket_Stats.csv");
    p.waitFor();
    // read this file into InputStream
    InputStream in = p.getInputStream();
    OutputStream output = new FileOutputStream("Sorted_Bucket_Stats.csv");
    System.out.println(IOUtils.copy(in,output));
    output.flush();
    output.close();
2
  • 2
    why don't you use the -o flag of the sort command? Commented Aug 6, 2013 at 0:09
  • you are a saint. make this an answer so i can thank you Commented Aug 6, 2013 at 0:21

1 Answer 1

2

Instead of handling the output in Java, you can use the

-o or --output=FILE

flag of the sort command and pass a filename for the output.

If you pass the same filename as the input, it will be overwritten.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.