1

I tried the code below but it doesn't work. Nevertheless, if I try to cat the file, it works and prints the whole content of the file.

But the reason I tried using awk is that I don't need the whole content, I only need some parts of each line.

Runtime r = Runtime.getRuntime();
Process p = r.exec("awk -F\":\" '/in/ {print $3}' file.awk"); 
p.waitFor();
BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println("esto es una \"prueba\"");
String valor = "";
while ((valor = in.readLine())!= null){
    System.out.println(valor);
}
Kulasangar
  • 9,046
  • 5
  • 51
  • 82

2 Answers2

2
jawk

is the java implementation of awk. Please follow this link for an overview: http://jawk.sourceforge.net/

Yeasir Arafat Majumder
  • 1,222
  • 2
  • 15
  • 34
2

Why would you want to run awk for a problem that is so trivial? If the line contains the string "in", split it on ":" and return the third field:

BufferedReader reader = new BufferedReader(new FileReader(filename));
while(String line = reader.readLine()) {
    if (line.indexOf("in") >= 0) {
        String[] fields = line.split(":");
        System.out.println(fields[2]);
    }
}
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Michael Vehrs
  • 3,293
  • 11
  • 10