Please provide information on your attempts to resolve.
Until so, we will refrain from sharing any guidance.
The purpose of this Board is the assist users in solving their problems. We are not a coding service. Further, we are not a homework service - and sometimes posts appear to be an attempt to have someone solve a school assignment.
Finally, we urge all members of the Forum to NOT post a solution to this question until effort to resolve is demonstrated.
Thanks for showing us your efforts, as mentioned by Joeyg please always spend sometime while posting any question, provide more information(eg--> your O.S name, sample Input_file and expected output_file in code tags).
If you want to search a specific string in all the .txt files and want to print only those file names which have them inside it, then following may help you in same.
If all of the files are in a single directory (not spread out among subdirectories), you could try the following first:
cd /tmp
grep -FHi 'Calling appalert' *.log
or, if you just want the names of files containing that string (with a case insensitive match):
cd /tmp
grep -Fli 'Calling appalert' *.log
These might file with "argument list too long" errors depending on how many thousands of files you have, but it is easy to try it. And, if it works, it will hundreds or thousands of times faster that performing a grep on each file individually. If they won't work, you'll know quickly.
Note that I added a -F option to grep . Searching for fixed strings (even if you're doing a case-insensitive match), is faster than going through the extra complexity of matching regular expressions.
If all of the log entries use the same case, dropping the -i option will also make it run faster.
The grep -l "Calling appalert" gives the pathnames of the files that have a line with Calling appalert .
Do you want something else?
Then give an example: a sample of an input file with a matching and a non-matching line, and the expected output.
BmmRaiseAlert.sh::308: AlertConfigResult [MatchedOn=033A,Appalert=A60107,Description=eRIC for MWW not processed messages for 5 minutes]
BmmRaiseAlert.sh::320: Calling BuildXHTMLForBmtm.sh with Bmm File [/opt/BMC/BMTM/RFRAlertingIntegration/BmmOutputFiles/BMMEventOutput.1508657897.215.812]
BmmRaiseAlert.sh::323: Call to BuildXHTMLForBmtm.sh complete
BmmRaiseAlert.sh::365: Calling appalert with args [ -l 3 -a MQ -e A60107 -f gbahevpl41.krf.express.RFR -u "http://messagemonitor.krf.express.RFR/BMTM/alerts/BMMEventOutput.1508657897.215.812.html" -m "gbahevpl41.krf.express.RFR:QPAHECL1:QTW1.BOQ.109 ==> eRIC for MWW not processed messages for 5 minutes"]
BmmRaiseAlert.sh::367: Call to appalert completed
BmmRaiseAlert.sh::369: Completed successfully
I want out from each file with file name after grepping the value into a single file.. For example
Name of first log file -> line starting with "AlertConfigResult" and starting with "Calling appalert" and "last line"
BmmRaiseAlert.sh.201710220838.6155.logfile.log ->BmmRaiseAlert.sh::308: AlertConfigResult [MatchedOn=033A,Appalert=A60107,Description=eRIC for MWW not processed messages for 5 minutes]
Calling appalert with args [ -l 3 -a MQ -e A60107 -f gbahevpl41.krf.express.RFR -u "http://messagemonitor.krf.express.RFR/BMTM/alerts/BMMEventOutput.1508657897.215.812.html" -m "gbahevpl41.krf.express.RFR:QPAHECL1:QTW1.BOQ.109 ==> eRIC for MWW not processed messages for 5 minutes"]
BmmRaiseAlert.sh::369: Completed successfully
Name of second log file -> line starting with AlertConfigResult and Calling appalert and last line
Name of n log file -> line starting with AlertConfigResult and Calling appalert and last line
we can ignore first 22 characters like "BmmRaiseAlert.sh::369:"
---------- Post updated at 03:33 AM ---------- Previous update was at 03:22 AM ----------
i tried below
cat BmmRaiseAlert.sh.201710220838.6155.logfile.log| egrep 'Calling appalert|Completed'
BmmRaiseAlert.sh::365: Calling appalert with args [ -l 3 -a MQ -e A60107 -f gbahevpl41.krf.express.RFR -u "http://messagemonitor.krf.express.RFR/BMTM/alerts/BMMEventOutput.1508657897.215.812.html" -m "gbahevpl41.krf.express.RFR:QPAHECL1:QTW1.BOQ.109 ==> eRIC for MWW not processed messages for 5 minutes"]
BmmRaiseAlert.sh::369: Completed successfully
but i need to read each file and save with file name front of the output..
Example
BmmRaiseAlert.sh.201710220838.6166.logfile.log
BmmRaiseAlert.sh::365: Calling appalert with args [ -l 3 -a MQ -e A60107 -f gbahevpl41.krf.express.RFR -u "http://messagemonitor.krf.express.RFR/BMTM/alerts/BMMEventOutput.1508657897.215.812.html" -m "gbahevpl41.krf.express.RFR:QPAHECL1:QTW1.BOQ.109 ==> eRIC for MWW not processed messages for 5 minutes"]
BmmRaiseAlert.sh::369: Completed successfully
BmmRaiseAlert.sh.201710220838.6177.logfile.log
BmmRaiseAlert.sh::365: Calling appalert with args [ -l 3 -a MQ -e A60107 -f gbahevpl41.krf.express.RFR -u "http://messagemonitor.krf.express.RFR/BMTM/alerts/BMMEventOutput.1508657897.215.812.html" -m "gbahevpl41.krf.express.RFR:QPAHECL1:QTW1.BOQ.109 ==> eRIC for MWW not processed messages for 5 minutes"]
BmmRaiseAlert.sh::369: Completed successfully
As Don stated already, the -i option makes things slower, and is not required here.
The problem was that the (useless) use of cat the file names disappear:
cat *.log | egrep 'Calling appalert|Completed'
because egrep sees only one input stream.
Simply let egrep open the files, so it sees the file names and even prefixes them by default.
egrep 'Calling appalert|Completed' *.log
If you want to ensure it prefixes the file name even if there is only one log file, then do as Don suggested
egrep -H 'Calling appalert|Completed' *.log
or, if your grep -E or egrep does not support the -H option, use the /dev/null trick