Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java app and grep - how can I independently process command output passed to grep with two regexs?

I have a Java application using a SSH connection, remotely running CLI commands. For a specific command, I would like to pipe the command's output through two regular expressions, finding two correlated subsets of the overall output and return that output back to my program.

For each of the two regular expressions: <RE1> & <RE2>, I would like to format the resulting outputs: <RE1out> & <RE2out> via <action1> & <action2> respectively; then return the final result, for example (please excuse the pseudo shell-script):

<command> | grep -e <RE1> -e <RE2> | (<REout1> given to <action1> and <REout2> given to   <action2>) yields <final_output>
like image 360
bn. Avatar asked Feb 02 '26 22:02

bn.


1 Answers

Try this

<command> | tee >(grep -e <RE1> | <action1>) >(grep -e <RE2> | <action2>)
like image 162
aioobe Avatar answered Feb 05 '26 13:02

aioobe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!