Piping with grep

Hi everybody,

I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form).

I am trying to extract some ids from within this file, which have certain parameters.
For example, some Of my IDs have the term 'No hit results' connected to them.
This is what I am trying to extract.
this is how it looks loike:

Query= ssc-miR-345-3p_st

Length=21

RID: 1307544734-17235-35154543375.BLASTQ1

***** No hits found *****

Lambda     K      H
    1.37    0.711     1.31 

Gapped
Lambda     K      H
    1.37    0.711     1.31 

Effective search space used: 0

In the complete file I have 15517 'Query=' and for 389 of them I can also find 'No hits found'.

My Qeustion is how can I found out which Queries are connected to this 'No hits'.

I tried it with :

split -a 5 -p '/Query=' filename

grep -lr 'No' . | grep 'Query='

But this doesn't work.

I just don't understand how to grep in many files and than pipe it to a second grep option.

I would be happy for any help.
Thanks

Assa

Try:

awk '/Query=/{s=$0}/No hits found/{print s}' file
1 Like

Or the with grep :slight_smile:

egrep "Query=|No hits found" file

thanks. Yes works great and fast.

@fpmurphy - sorry for the double posting. it wasn't deliberate.

I would still like to know if there is a possibility to search in a list of files with grep like I did in my example and pipe them to to a second grep command to look for a different term.

I am asking because I will probably need to work on the list of file with other terms, which might have different structure. than this one here.

Thanks again

See my previous post, and yes you can further pipe the output to other grep/egrep.

This is not the right solution, as it give all 'Query=' items. I than need to work further on the output.

Thanks

Yes my bad. Here is a little hack, although I`d go for awk in this case.

Below is very bad code and may break since it is file-order dependent. Use the awk example :slight_smile:

egrep "Query|No hits" test | grep -B 1 "No hits"