title: awk commands in Java
body: <p>I want to use awk command line in Java. For that, I have this code (I saw this code in a tutorial):</p>
  
  <pre><code>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(); 
  </code></pre>
  
  <p>In this example my code prints the first column of the file. </p>
  
  <pre><code>10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  10
  </code></pre>
  
  <p>I want to print the output in a file but I can't figure it out. </p>