grep until a space


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep until a space
# 1  
Old 03-16-2010
Data grep until a space

This is probably common knowledge, but I am a beginner at bioinformatics!

I want a list of my sequence names, without sequence or any of the free text after the space. This is some example file:

>cow|68989024|dbj|AB107582.1| Uncultured bacterium gene for 16S rRNA, partial se
quence, clone: 2-G12
AGAGTTTGATCCTGGCTCAGGACGAACGCGGCGGCGTGCCTAACACATGCAAGTCGAACGGAGATATACG
CTGATTTGATGAAAGCTTGCTTTTGGATTTTCTTGTGTATCTTAGTGGCGGACGGGCGAGTAACGCGTGA
>cow|68989023|dbj|AB107581.1| Uncultured bacterium gene for 16S rRNA, partial se
quence, clone: 1-H07
AGAGTTTGATCCTGGCTCAGGATGAACGCTGGCGGCGTGCCTAATACATGCAAGTCGAGCGAACCACTTC
GGTGGTGAGCGGCGAACGGGTGAGTAACACGTAGGTGATCTGCCCATCAGACGGGGACAACGATTGGAAA

And I want the output to look like this:

>cow|68989024|dbj|AB107582.1|
>cow|68989023|dbj|AB107581.1|

I assume there is some way of using grep and terminating how much is returned? but I have no idea.

Thanks so much!
# 2  
Old 03-17-2010
Try:

Code:
awk -F"|"  '/^>/ { OFS="|"; $NF=""; print;}' file

# 3  
Old 03-17-2010
Using sed
Code:
sed 's/\(.*| \)\(.*\)/\1/g;/^>cow/!d' input

Here the input file contains your input data.
# 4  
Old 03-17-2010
Quote:
Originally Posted by thillai_selvan
Using sed
Code:
sed 's/\(.*| \)\(.*\)/\1/g;/^>cow/!d' input

Here the input file contains your input data.
You dont need to use the second reg-exp grouping...

Code:
 
sed 's/\(.*| \).*/\1/g;/^>cow/!d'  file

# 5  
Old 03-17-2010
Code:
 
cat file | cut -d'|' -f 1-4  | sed '2d' | grep ">"

# 6  
Old 03-17-2010
MySQL

See the following code to match the pattern and give the following Output:

>cow|68989024|dbj|AB107582.1|
>cow|68989023|dbj|AB107581.1|


Code:
egrep --color -o "^[>cow|](.*?[|])" fine_name

# 7  
Old 03-17-2010
Quote:
Originally Posted by murugaperumal
Code:
 
cat file | cut -d'|' -f 1-4  | sed '2d' | grep ">"

Code:
cat file | cut -d'|' -f 1-4

can be written as
Code:
 
cut -d'|' -f 1-4  file

Uselesss use of cat (UUOC) . Very useful to read a posting of one of our unix.com member "era"

Useless Use of Cat Award
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep the words with space between?

see I have a text like: 27-MAY 14:00 4 aaa 5.30 0.01 27-MAY 14:00 3 aaa 0.85 0.00 27-MAY 14:00 2 aaa 1.09 0.00 27-MAY 14:00 5 aaa 0.03 0.00 27-MAY 14:00... (3 Replies)
Discussion started by: netbanker
3 Replies

2. Shell Programming and Scripting

grep to remove blank space

Hi All, Need help to grep blank and copy to file. I have a file in below format dns1dm06_10, dns2dm02_04, dbidub,10000000c9a46d0c gbpuhci,10000000c948b00a ibtur001,10000000c9a1ccda yubkbtp1,10000000c93fec5b I need to copy to all lines which doesn't have wwn >> no-wwn.txt 1... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

3. Shell Programming and Scripting

Eliminating space constraint in grep

here in the below code just a space between 'Info' and '(' is showing that the patter doesnt match... echo "CREATE TABLE Info (" | grep -i "CREATE TABLE Info (" | wc | awk -F' ' '{print $1}' 1 echo "CREATE TABLE Info (" | grep -i "CREATE TABLE Info (" | wc | awk -F' ' '{print $1}' 0 ... (9 Replies)
Discussion started by: vivek d r
9 Replies

4. Shell Programming and Scripting

grep for a string until instance of a space

Hey guys, I'm having a bit of trouble getting this to work using either sed or grep. It's possible awk might be the ticket I need as well, but my regulat expression skills aren't quite up to the task for doing this. I'm looking to grep for the string ERROR from the following log up until any... (6 Replies)
Discussion started by: terrell
6 Replies

5. Shell Programming and Scripting

Grep empty space and sort

Hi Expert, Kindly request for your expertise in this matter. I have below output: 12.125.124.173,xx1.common.com 12.125.124.174,xx2.common.com 12.125.124.175,xx3.common.com 12.125.124.176, 12.125.124.177, 12.125.124.178, 12.125.124.179,xx4.common.com 12.125.124.180,xx5.common.com... (8 Replies)
Discussion started by: regmaster
8 Replies

6. Shell Programming and Scripting

How to grep space?

Hi, I want to know how to grep space. Eg: input file contains 1565432 432 546 3514432 432 545 6541332 432 354 5464412 565 355 8456145 546 534 5632465 432 654 From this i need output of the lines which has 432 which are bold. My requirement is whenever 432 comes... (3 Replies)
Discussion started by: rakeshbharadwaj
3 Replies

7. Shell Programming and Scripting

Matching white space through Grep

Hello All, I am trying to match white space in patterns through - Grep I tried ] & ] but none of them worked. Then I tried Perl extension '\s' and it worked. So just wanted to know if ] & ] are still supported or have they become deprecated. However they have been mentioned in the... (3 Replies)
Discussion started by: paragkalra
3 Replies

8. Shell Programming and Scripting

grep : search a long char contain space

Hi, i have to search for a char like that : export var1="i am not happy /not happy" with a command like : grep $var1 file but this not working with me !!! thank you in advance. (2 Replies)
Discussion started by: tizilfin
2 Replies

9. Shell Programming and Scripting

To grep multiple patterns with space in between them......

Hii... Every One...... I want to grep multiple patterns with space in between them. For eg : I have a file which contains following : red cat every one new one you are an ox take one Now, what I want to do is to grep " you are" , "an ox" and "red cat" from this file. Any help........ (5 Replies)
Discussion started by: prashantshukla
5 Replies

10. UNIX for Dummies Questions & Answers

Change field separator of grep from : to space

Hi, All, I wonder how to change the field separator of grep from : to space when use grep to display. for example when I use grep -e 'pattern1' -e 'pattern2' -n filename to find patterns, it use : to separate patterns, but I want to use blank space. is there an option I can set to... (2 Replies)
Discussion started by: Jenny.palmy
2 Replies
Login or Register to Ask a Question