467,145 Members | 1,043 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

parsing text

Hi,
Can anyone please tell me how should I be parsing the following text file so that I could retrieve just the text following FUNCTION: and next two lines without the CC?

--------------------- Input text file ---------------------------
CC -!- FUNCTION: Involved in the secretion of a proteinaceous elicitor of
CC the hypersensitivity response in plants. Also required for
CC pathogenicity on host plant.
CC -!- SIMILARITY: Belongs to the hrpJ/yopN family.
---------------------------------------------------------------------

This is how I started with:
Expand|Select|Wrap|Line Numbers
  1. if($ln =~ /^CC/){
  2. $ln =~ s/\n//g;
  3. next;
  4. }
  5.  
Thanks
Nov 15 '07 #1
  • viewed: 894
Share:
2 Replies
KevinADC
Expert 2GB
A very contrived suggestion:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $output = '';
  4. while( <DATA> ) {
  5.    if (/\QCC -!- FUNCTION:\E\s*([\s\S]+)/) {
  6.       $output = $1;
  7.       $output .= <DATA>;
  8.       $output .= <DATA>;
  9.       $output =~ s/CC\s+//g;
  10.       last;
  11.    }
  12. }
  13. print $output;
  14. __DATA__
  15. CC -!- FUNCTION: Involved in the secretion of a proteinaceous elicitor of
  16. CC the hypersensitivity response in plants. Also required for
  17. CC pathogenicity on host plant.
  18. CC -!- SIMILARITY: Belongs to the hrpJ/yopN family.
Nov 16 '07 #2
Thanks a lot, KevinADC.


A very contrived suggestion:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $output = '';
  4. while( <DATA> ) {
  5.    if (/\QCC -!- FUNCTION:\E\s*([\s\S]+)/) {
  6.       $output = $1;
  7.       $output .= <DATA>;
  8.       $output .= <DATA>;
  9.       $output =~ s/CC\s+//g;
  10.       last;
  11.    }
  12. }
  13. print $output;
  14. __DATA__
  15. CC -!- FUNCTION: Involved in the secretion of a proteinaceous elicitor of
  16. CC the hypersensitivity response in plants. Also required for
  17. CC pathogenicity on host plant.
  18. CC -!- SIMILARITY: Belongs to the hrpJ/yopN family.
Nov 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by ralphNOSPAM@primemail.com | last post: by
3 posts views Thread by Pir8 | last post: by
7 posts views Thread by Lucas Tam | last post: by
4 posts views Thread by Earl | last post: by
2 posts views Thread by JaythePCguy@gmail.com | last post: by
9 posts views Thread by ankitdesai@gmail.com | last post: by
13 posts views Thread by Chris Carlen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.