SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing multi fasta sequence file using Perl newbie2this Bioinformatics 9 09-11-2013 04:48 AM
Parsing a VCF file for indels bnfoguy Bioinformatics 1 07-12-2012 10:19 AM
Dindel crash whilst parsing bam-sorted file michalkovac Bioinformatics 8 02-16-2012 06:56 PM
Retrieve single rows from large pileup file cowman Bioinformatics 1 01-16-2011 01:40 PM

Reply
 
Thread Tools
Old 06-26-2013, 10:42 AM   #1
Shishir
Member
 
Location: Germany

Join Date: Nov 2012
Posts: 22
Default Parsing file to retrieve specific pattern

I have a txt file with several rows. Each row contains several words separated by space. I want to print the values which have pattern like amenXXXXXXX (where length of X string is different in many rows). I tried grep with -o option and some other one-liners but not able to print only the words that have the pattern like amen. Indeed I want the output like:

amen2wit
amen3grps
amen0qw
amen8dbskm.....

I will appreciate your expert suggestions.
Shishir is offline   Reply With Quote
Old 06-26-2013, 01:26 PM   #2
rhinoceros
Senior Member
 
Location: sub-surface moon base

Join Date: Apr 2013
Posts: 372
Default

Are all amenXXXXXXX in the same column? If yes, you could just:

cut -f N

Where N is the column number.
rhinoceros is offline   Reply With Quote
Old 06-26-2013, 01:53 PM   #3
dariober
Senior Member
 
Location: Cambridge, UK

Join Date: May 2010
Posts: 311
Default

Quote:
Originally Posted by Shishir View Post
I have a txt file with several rows. Each row contains several words separated by space. I want to print the values which have pattern like amenXXXXXXX (where length of X string is different in many rows). I tried grep with -o option and some other one-liners but not able to print only the words that have the pattern like amen. Indeed I want the output like:

amen2wit
amen3grps
amen0qw
amen8dbskm.....

I will appreciate your expert suggestions.
What about this:

Code:
echo "no pattern
amen
amenXXX
foo amenBLA foo2
etc" > mytext.txt

grep -o 'amen[^ ]*' mytext.txt
amen
amenXXX
amenBLA
How do you want to deal with the pattern occurring more than once per row, if that happens?
dariober is offline   Reply With Quote
Old 07-02-2013, 06:29 AM   #4
Shishir
Member
 
Location: Germany

Join Date: Nov 2012
Posts: 22
Default

Thanks you all !!

Quote:
Originally Posted by dariober View Post
What about this:

Code:
echo "no pattern
amen
amenXXX
foo amenBLA foo2
etc" > mytext.txt

grep -o 'amen[^ ]*' mytext.txt
amen
amenXXX
amenBLA
How do you want to deal with the pattern occurring more than once per row, if that happens?
Shishir is offline   Reply With Quote
Reply

Tags
awk, linux, parsing, perl, unix

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO