I have created a simple shell script where I print some output messages and I invoke a really long command which generates a very long log. I redirect the log generated by the command in a file named jobLog.log using this answer. So my code is this:


echo "Submiting a job to ...."

sudo command_with_huge_output > jobLog.log 2>&1 && echo "Job ended! Log at jobLog.log" 

I want to redirect one line from this log to the screen. When the job ends I use grep on the file like:

less jobLog.log | grep LineIwanttoFind 

and this returns a line I am interested to print while the command is running. How can I filter the line I want, and redirect it in the screen while the command is running? Of course I also want to send the full log in jobLog.log file.

Thanks for any suggestion


1 Answer 1


Use tee like this : command_with_huge_output | tee jobLog.log | grep 'LineYouWantToFind'

So all the standard output of the command_with_huge_output will go to the jobLog.log and to the pipe to grep.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .