Pull out multiple lines with grep patternfile | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Pull out multiple lines with grep patternfile

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-23-2013
FGPonce FGPonce is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 24 March 2013, 12:44 AM EDT
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Pull out multiple lines with grep patternfile

Hi,
I'm trying to get lines from a file using identifiers in the first two columns. I have used:

cat MasterFile.txt | grep -f Pattern.txt

and the lines I want display on screen. If I try to put them in a file the file is created but stays empty:

cat MasterFile.txt | grep -f Pattern.txt > output.txt

Also: If I use the whole pattern file (tested with 12 top lines from my pattern file to start) it doesn't even display on screen.....

Any ideas how I can do this? Very frustrating that the process seems to work but then hit the brick wall!!!
Sponsored Links
    #2  
Old 03-23-2013
risham risham is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 23 March 2013, 8:07 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
u can try cat MasterFile.txt | grep -f - Pattern.txt

this should work
Sponsored Links
    #3  
Old 03-23-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 31 August 2014, 12:26 AM EDT
Location: San Jose, CA, USA
Posts: 4,480
Thanks: 176
Thanked 1,503 Times in 1,275 Posts
Please use CODE tags!

If you don't show us the contents of MasterFile.txt and Pattern.txt, there isn't much we can do to figure out why your pipelines aren't working (although they could easily be made faster and more efficient by getting rid of the unneeded cat commands).

What system are you using. (Are you by any chance using any files produced on a Windows system with carriage return and newline characters at the end of each line instead of just a newline?)
    #4  
Old 03-23-2013
risham risham is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 23 March 2013, 8:07 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I have a file1 as
>NC_0123
>NC_0124
>NC_0125

and file 2
>NC_0123
ACGTGCGTC
>NC_0125
ACTGCGTCGTCG
>NC_0126
ACTGCGTGCGTCG

i want the output as
>NC_0123
ACGTGCGTC
>NC_0125
ACTGCGTCGTCG

i am using cat file1 | grep -A 1 -wf - file2 but its not working

P.S. have used the same command n number of times with the same type of files nad it works! God knws y its nt working here!

---------- Post updated at 04:48 AM ---------- Previous update was at 04:47 AM ----------

I am sry fr nt using code tags!
Sponsored Links
    #5  
Old 03-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 30 August 2014, 5:16 PM EDT
Location: Aachen, Germany
Posts: 4,145
Thanks: 67
Thanked 990 Times in 938 Posts
Hw abt wrt n pln Nglsh?

Nd, dnt hijack oths' threads!
Sponsored Links
    #6  
Old 03-23-2013
risham risham is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 23 March 2013, 8:07 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I am sorry If I offended someone in any way! I am really new to this forum and yes I am learning the rules now. I never meant to hijack any threads!! It's just that I was in a difficult situation and found a similar post in this thread so posted a reply.

Any solution to the above problem will be highly appreciated thanks!
Sponsored Links
    #7  
Old 03-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 30 August 2014, 5:16 PM EDT
Location: Aachen, Germany
Posts: 4,145
Thanks: 67
Thanked 990 Times in 938 Posts
I'd suggest you open a new thread and give FGPonce a chance to have his/her request worked upon and answered.
You might even want to delete / edit-to-nil your posts in this thread.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep multiple lines evelibertine UNIX for Dummies Questions & Answers 2 10-18-2011 01:13 AM
grep first occurrence but continue to next entry in patternfile newhavendweeb UNIX for Dummies Questions & Answers 2 06-09-2011 08:25 AM
grep command to find multiple strings in multiple lines in a file. ritikaSharma UNIX for Dummies Questions & Answers 2 12-17-2010 03:43 AM
How do you use pull data from multiple lines to do a for statement? scottzx7rr Shell Programming and Scripting 7 01-07-2010 10:43 AM
grep multiple lines cdunavent Shell Programming and Scripting 27 03-27-2005 06:23 AM



All times are GMT -4. The time now is 04:16 AM.