[英]Java app and grep - how can I independently process command output passed to grep with two regexs?
我有一個使用SSH連接的Java應用程序,遠程運行CLI命令。 對於特定的命令,我想通過兩個正則表達式來管道命令的輸出,找到整個輸出的兩個相關子集並將該輸出返回給我的程序。
對於兩個正則表達式中的每一個:< RE1 >&< RE2 >,我想格式化結果輸出:< RE1out >&< RE2out >分別通過< action1 >和< action2 >; 然后返回最終結果,例如(請原諒偽shell腳本):
<command> | grep -e <RE1> -e <RE2> | (<REout1> given to <action1> and <REout2> given to <action2>) yields <final_output>
試試這個
<command> | tee >(grep -e <RE1> | <action1>) >(grep -e <RE2> | <action2>)
我會使用這個臨時創建幾個臨時文件的過程,但仍然是一個單行:
command |
awk '/RE1/ {print >> "tmp1"} /RE2/ {print >> "tmp2"}' &&
{ action1 < tmp1; action2 < tmp2; rm tmp1 tmp2; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.