Visit Our UNIX and Linux User Community


Piping with grep


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Piping with grep
# 1  
Old 06-09-2011
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:
Code:
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 :
Code:
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
This User Gave Thanks to frymor For This Post:
# 2  
Old 06-09-2011
Try:
Code:
awk '/Query=/{s=$0}/No hits found/{print s}' file

These 2 Users Gave Thanks to Franklin52 For This Post:
# 3  
Old 06-09-2011
Or the with grep Smilie

Code:
egrep "Query=|No hits found" file

# 4  
Old 06-09-2011
MySQL

Quote:
Originally Posted by Franklin52
Code:
awk '/Query=/{s=$0}/No hits found/{print s}' 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
This User Gave Thanks to frymor For This Post:
# 5  
Old 06-09-2011
Quote:
Originally Posted by frymor
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 User Gave Thanks to click For This Post:
# 6  
Old 06-09-2011
Quote:
Originally Posted by click
Or the with grep

Code:
egrep "Query=|No hits found" file

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

Thanks
# 7  
Old 06-09-2011
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 Smilie

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

This User Gave Thanks to click For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #197
Difficulty: Easy
C# ranked higher than C according to the TIOBE Index for October 2019.
True or False?

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Piping to grep with pbpaste

cat file 1 aaa 2 bbb 3 ccc 4 ddd In TextEdit, I then copy the characters “ccc” to the clipboard. The problem is that the following command gives no output: bash-3.2$ pbpaste | grep - file Desired output: 3 ccc What should the syntax be for that command? I am using MacOS El... (3 Replies)
Discussion started by: palex
3 Replies

2. Shell Programming and Scripting

Piping through grep/awk prevents file write

So, this is weird... I'm running this command: iotop -o -P -k -bt -d 5 I'd like to save the output relelvant to rsyslogd to a file, so I do this: iotop -o -P -k -bt -d 5 | grep rsyslogd >> /var/log/rsyslogd Nothing is written to the file! I can write the full output to the file: ... (2 Replies)
Discussion started by: treesloth
2 Replies

3. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

4. Shell Programming and Scripting

piping from grep to awk without intermediate files

I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output which was given by the grep. sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* Output: ... (6 Replies)
Discussion started by: siteregsam
6 Replies

5. Ubuntu

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'... (1 Reply)
Discussion started by: frymor
1 Replies

6. Shell Programming and Scripting

Piping STDOUT as pattern to grep or sed

$>cat file.txt 123 d3 234 abc 3 zyf 23 124 def 8 ghi kz0 ... ... I have the following output on the screen through <some command>. $> <some command> abc def ghi ... ... I have to search for each of these patterns in the file.txt and print the lines in file.txt matching the... (4 Replies)
Discussion started by: VNR
4 Replies

7. UNIX for Dummies Questions & Answers

Piping GREP

Hi, I need to use a double grep so to speak. I need to grep for a particular item say BOB and then for each successful result I need to grep for another item say SMITH. I tried grep "BOB" filename | grep "SMITH" but it does not seem to work. I can achieve my desired result using an... (12 Replies)
Discussion started by: mojoman
12 Replies

8. Shell Programming and Scripting

Grep causing long delay (batching) whilst piping

Hi all. I have a problem at work which I have managed to break down into a simple test scenario: I have written a monitoring script that outputs every second the status of various processes, but for now, lets just print the date input.sh: while true do date sleep 1 done This... (9 Replies)
Discussion started by: spudtheimpaler
9 Replies

9. Shell Programming and Scripting

question about grep, cut, and piping

Howdy folks, I am fairly new to scripting but have lost of expirience in c++, pascal, and a few other. I am trying to complete a file search script that is sent a file name containing data to search that is arranged like this "id","name","rating" "1","bob","7" etc and an argument to... (1 Reply)
Discussion started by: dyrt
1 Replies

10. UNIX for Dummies Questions & Answers

piping the output of find command to grep

Hi, I did not understand why the following did not work out as I expected: find . -name "pqp.txt" | grep -v "Permission" I thought I would be able to catch whichever paths containing my pqp.txt file without receiving the display of messages such as "find: cannot access... Permisson... (1 Reply)
Discussion started by: 435 Gavea
1 Replies

Featured Tech Videos