I want to use awk command line in Java. For that, I have this code (I saw this code in a tutorial):
Map map = new HashMap();
map.put("file", new File(fileDirectory));
CommandLine cmdLine = new CommandLine("awk");
cmdLine.addArgument("{print $1}", false);
cmdLine.addArgument("${file}");
cmdLine.setSubstitutionMap(map);
System.out.println(cmdLine.toString());
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(10000);
DefaultExecutor executor = new DefaultExecutor();
executor.setWatchdog(watchdog);
executor.execute(cmdLine, resultHandler);
resultHandler.waitFor();
In this example my code prints the first column of the file.
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
I want to print the output in a file but I can't figure it out.