I am trying to use awk from java. I wrote below code but there is no output.
public class ShellScriptExecution {
public static void main (String[] a) {
ShellScriptExecution shellsc = new ShellScriptExecution();
String command = "awk '/Ayushi/ {print}' /home/ayushi/Desktop/testAwk.txt ";
String op = shellsc.execute(command, a);
System.out.println(op);
}
private String execute(String command, String[] a) {
StringBuffer sb = new StringBuffer();
Process p;
try {
//
//
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
sb.append(line + "\n");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return sb.toString();
}
}
Please provide some help on how to use awk in java? And if any other way to do it ?