I ran a for loop with several commands over different files in shell under nohup. I need to get the log values of one of the commands which gets printed on the terminal (in this case, in the nohup.out file). I tried to do an egrep and find the pattern. Though, I got my log values, I do not know it belongs to which file. I want to print the file name along with the values. Is there a way to do so ? Any help would be appreciated. Thanks in advance.

My nohup.out file looks like

100000 GFF lines processed.
200000 GFF lines processed.
300000 GFF lines processed.
400000 GFF lines processed.
500000 GFF lines processed.
600000 GFF lines processed.
700000 GFF lines processed.
about 10000 lines 
__no_feature    XXXX
__ambiguous 102723
__too_low_aQual 0
__not_aligned   0

This goes on for several different files. I want to extract the four lines which has "__no_feature" etc with their input file names.

I used egrep :

egrep "__no_feature|__ambiguous|__too_low_aQual|__not_aligned|__alignment_not_unique" nohup.out

But I got only the patterns and not the file names.

  • Please include your code and sample input/output so that the requirement is clear. – codeforester Sep 20 at 4:51
  • Hello Inquisitive8995, welcome to SO. In order for us to help you, please add more details on what you've tried. Refer stackoverflow.com/help/how-to-ask to ask good questions. – vishnu narayanan Sep 20 at 5:04
  • Just edited my question. Hope it is better. – Inquisitive8995 Sep 20 at 5:07

Try using egrep -H option

egrep -H "__no_feature|__ambiguous|__too_low_aQual|__not_aligned|__alignment_not_unique" nohup.out

-H option is used view the file name along with the matched line
-h option is used o hide the filename from the matched line

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.