linuxshell

How to grep the keywords in two different file


Below two scripts starts at same timestamp but I want to differentiate the output filename for logging purpose. Once output is created then we need to search the specific keyword in two different output files.

Shell script 1
Test1=`command 2>output.txt`

Shell script 2
Test1=`command 2>output.txt`

Shell script 3 and so on

Solution

  • How about using the process-id?

    OUTPUT_FILE_NAME="output-$(date +%C%y%m%d%H%M%s)-$$.txt"
    comannd 2>"${OUTPUT_FILE_NAME}"
    grep "stuff to look for" "${OUTPUT_FILE_NAME}"