Reputation: 11
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);
}
Upvotes: 1
Views: 3861
Reputation: 3363
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]);
}
}
Upvotes: 2
Reputation: 1264
jawk
is the java implementation of awk. Please follow this link for an overview: http://jawk.sourceforge.net/
Upvotes: 2