LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-12-2011, 09:10 PM   #16
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45

Code:
$ ruby -00 -ne 'puts $_ if /HUMAN/' file
>Q53HC2_HUMAN/218-253 PF10417.3;1-cysPrx_C;
ALQYVETHGEVCPANWTPDSPTIKPSPAASKEYFQK

>B4DZA5_HUMAN/287-857 PF04547.6;Anoctamin;
IRKYYGEKIGIYFAWLGYYTQMLLLAAVVGVACFLYGYLNQDNCTWSKEV
CHPDIGGKIIMCPQCDRLCPFWKLNITCESSKKLCIFDSFGTLVFAVFMG
VWVTLFLEFWKRRQAELEYEWDTVELQQEEQARPEYEARCTHVVIDEITQ
EEERIPFTAWGKCIRITLCASAVFFWILLIIASVIGIIVYRLSVFIVFSA

>ANFC_HUMAN/94-126 PF00212.12;ANP;
NARKYKGANKKGLSKGCFGLKLDRIGSMSGLGC
 
Old 04-12-2011, 09:26 PM   #17
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
awk 'BEGIN{RS=ORS="\n\n";FS="\n"} /HUMAN/' human.txt
>Q53HC2_HUMAN/218-253 PF10417.3;1-cysPrx_C;
ALQYVETHGEVCPANWTPDSPTIKPSPAASKEYFQK

>B4DZA5_HUMAN/287-857 PF04547.6;Anoctamin;
IRKYYGEKIGIYFAWLGYYTQMLLLAAVVGVACFLYGYLNQDNCTWSKEV
CHPDIGGKIIMCPQCDRLCPFWKLNITCESSKKLCIFDSFGTLVFAVFMG
VWVTLFLEFWKRRQAELEYEWDTVELQQEEQARPEYEARCTHVVIDEITQ
EEERIPFTAWGKCIRITLCASAVFFWILLIIASVIGIIVYRLSVFIVFSA

>ANFC_HUMAN/94-126 PF00212.12;ANP;
NARKYKGANKKGLSKGCFGLKLDRIGSMSGLGC



Cheers,
Tink

Last edited by Tinkster; 04-12-2011 at 09:58 PM.
 
1 members found this post helpful.
Old 04-13-2011, 02:22 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
If the blank lines between aren't required it can be even simpler still:
Code:
awk '/HUMAN/' RS="" file
 
Old 04-13-2011, 02:23 AM   #19
Tauro
LQ Newbie
 
Registered: Apr 2011
Posts: 24

Original Poster
Rep: Reputation: 1
@kurumi and tinkster
d input data is not in paragraph form.. No spaces between consecutive entries starting with ">"
The below one works.. but i also need the line containing the pattern1 that is "HUMAN"
Code:
ruby -0777 -ne 'puts $_.scan(/pattern 1(.*?)pattern 2/m)' file
 
Old 04-13-2011, 02:33 AM   #20
Tauro
LQ Newbie
 
Registered: Apr 2011
Posts: 24

Original Poster
Rep: Reputation: 1
Alright.. got the solution..
Since there was no spacing in the file.

Code:
sed '/>/{x;p;x}' file | awk 'BEGIN{RS=ORS="\n\n";FS="\n"} /HUMAN/'
Thanks all
 
Old 04-13-2011, 06:09 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
I am curious as to what value the sed is supposedly adding?
Both of the following yield me the same output:
Code:
sed '/>/{x;p;x}' file | awk 'BEGIN{RS=ORS="\n\n";FS="\n"} /HUMAN/'

awk 'BEGIN{RS=ORS="\n\n";FS="\n"} /HUMAN/' file
Also the FS is not really required so it could just be:
Code:
awk 'BEGIN{RS=ORS="\n\n"} /HUMAN/' file
 
Old 04-14-2011, 04:57 AM   #22
Tauro
LQ Newbie
 
Registered: Apr 2011
Posts: 24

Original Poster
Rep: Reputation: 1
The input data has no blank lines the reason why this one liner didnt work
Code:
awk 'BEGIN{RS=ORS="\n\n";FS="\n"} /HUMAN/' file
it gave the entire data instead.
and so I used
Code:
sed '/>/{x;p;x}' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep for multiple patterns???? lucastic Linux - Software 4 08-06-2010 07:07 PM
grepping all the lines between 2 patterns raghu123 Programming 2 11-04-2008 02:24 AM
commands for bash script that handles files of varying number of lines BBFeltham Linux - Newbie 1 07-26-2008 11:18 AM
grep patterns tekmann33 Linux - Newbie 2 07-14-2008 02:25 PM
how to grep 5k patterns at a time? xiawinter Linux - Software 9 12-29-2007 02:18 AM


All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration