Multiple results as input to grep or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple results as input to grep or awk
# 1  
Old 11-20-2013
Multiple results as input to grep or awk

Hi:
This is my first post in this forum. apologies if I am asking question that has been asked here multiple times.


I wrote a python script that prints list of identifiers. I have another file notoriously big and with no particular format.

I plan to search the identifiers in this file and print line that contains that pattern and next line.

Code:
$ python get_IDs.py | sort
TCONS_00142932
TCONS_00142933
TCONS_00142934
TCONS_00142935

I want to search these 4 patterns in another file MYBIGFILE.pep and print line that has this TCONS_00142932 and following line.


I am currently doing one by one...

Code:
$ cat transcripts.fasta.transdecoder.pep | grep -A1 'TCONS_00142932'
>cds.TCONS_00142932
MIINWNQVSVLWKCLLKQSASYQDRRQSWRRASMKETNRRKSLHPIHQGITELSRSISVD

How can I automate this using either awk or grep through piping..


something like:

Code:
$ python get_IDs.py | sort | grep -A1 'PAT$1'...

>cds.TCONS_00142932
MIINWNQVSVLWKCLLKQSASYQDRRQSWRRASMKETNRRKSLHPIHQGITELSRSISVD
>cds.TCONS_00142933
KYRSNNWNQVSVLQSASYQDRRQSWRRASMKETNRRKSLHPIHQGITELSRSISVD
>cds.TCONS_00142934
MTSVTRSEIIDEKGPVMSKTHDHQLESSLSPVEVFAKTSASLEMNQGVSEERIHLGSSPK
....

Thanks.
Adrian
Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 11-20-2013 at 08:14 PM..
# 2  
Old 11-20-2013
If you shorten your previous grep to
Code:
grep -A1 'TCONS_00142932' transcripts.fasta.transdecoder.pep

you have freed the stdin, and can use it for the other input:
Code:
python get_IDs.py | sort | grep -A1 -f - transcripts.fasta.transdecoder.pep

P.S. please wrap your code in [code] tags!
# 3  
Old 11-20-2013
Hi,
You can try:
Code:
grep -A1 -f <(python get_IDs.py | sort | grep -v '^$') bigfile.pep

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple Results of Grep in one Line/String?

Hello, I have a Textfile sees like this "Word1":aksdfjaksdf "Word2":askdfjalsdkfdlsjfasldfj "This is Word3":asdfkjalskdfj what i need is a string which sees like this Word1;Word2;This is Word3 Conclusion always the text within "" which is before the : i tried it with grep.... (10 Replies)
Discussion started by: SwordMaster
10 Replies

2. Shell Programming and Scripting

Combine awk Or Grep Input

grep -ia '^Windows Installer' Galant01.txt Galant02.txt | awk -F '\t' '{print substr($1,1,index($1,":")) $4 "<br>"}' ; The output produces: Galant01.txt:Manual<br> Galant02.txt:Manual<br> It will be good to show instead: The output produces: Galant01.txt,Galant02.txt:Manual<br> The idea... (2 Replies)
Discussion started by: alvinoo
2 Replies

3. UNIX for Dummies Questions & Answers

Multiple string input in a awk

Hi everybody, I just start my learning about Linux. So, if you can help me, it would be very good ! I have already find the possibility to find the position of a character regular expression in a line with the help of awk : test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL My script is... (2 Replies)
Discussion started by: thewizarde6
2 Replies

4. Shell Programming and Scripting

Grep multiple string from input

How can I grep multiple strings from an input, strings are separated by space. Strings to grep: 7680FR 6791HH 1234AA Input: AA 7680FR AA 6891HH AA 6791UA BB 9834HA BB 1434AB DD 1234AA DD 6991HH DD 6791HH Required output: AA 7680FR (9 Replies)
Discussion started by: aydj
9 Replies

5. Shell Programming and Scripting

FOR loop with multiple files as input and awk

Hi all , i want to pass multiple files as input to a for loop for i in file1 file2 file3 do some awk action < $i >> $i.out done but im getting error in that for loop is the way i use to pass files to awk using for correct and 2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies

6. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

7. Shell Programming and Scripting

how to give multiple csv files as input in awk

Hi All, I am new to shell scripting..My problem is i want to give multiple csv files as input to awk script and process the data into one file.. My input file is File1 File2 File3 Product Location Period SalesPrice A x 8/11/2010 ... (7 Replies)
Discussion started by: kvth
7 Replies

8. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

9. Shell Programming and Scripting

Multiple input field Separators in awk.

I saw a couple of posts here referencing how to handle more than one input field separator in awk. I figured I would share how I (just!) figured out how to turn this line in a logfile: 90000000000000000000010001 name... (4 Replies)
Discussion started by: kinksville
4 Replies

10. Shell Programming and Scripting

Multiple Grep Results - Formatting

Hello, Perhaps someone here can help with this. I'd like to grep a plain text file for a word and output each line containing a word found to a seperate line instead of back to back. Examples: Basic command: cat file.txt > grep -i CAT > results.txt file.txt: The cat said meow The... (7 Replies)
Discussion started by: sysera
7 Replies
Login or Register to Ask a Question