我正在尝试使用 java 中的 awk。我写了下面的代码,但没有输出。
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();
}
}
请提供一些有关如何在java中使用awk的帮助?如果有其他方法可以做到吗?
一只斗牛犬
相关分类