Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Unable to grep

UNIX for Dummies Questions & Answers


Tags
grep

 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
gotamp's Unix or Linux Image
gotamp gotamp is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 December 2016, 11:13 AM EST
Posts: 29
Thanks: 17
Thanked 0 Times in 0 Posts
Unable to grep

I have a file with 2 lines of code

Code:
Rome is in Romeo
Romeo is in Rome

How do I grep, so that only last line would be the outcome.
sample output

Code:
Romeo is in Rome

I have tried with all possible greps but its resulting in both the lines in output.

Please help.
Sponsored Links
    #2  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 December 2017, 4:36 AM EST
Location: San Jose, CA, USA
Posts: 10,790
Thanks: 592
Thanked 3,772 Times in 3,220 Posts
When you say you have tried all possible greps, I find that hard to believe. Please show us what you have tried.

Is this a homework assignment?
The Following User Says Thank You to Don Cragun For This Useful Post:
gotamp (05-26-2016)
Sponsored Links
    #3  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
gotamp's Unix or Linux Image
gotamp gotamp is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 December 2016, 11:13 AM EST
Posts: 29
Thanks: 17
Thanked 0 Times in 0 Posts
Thanks Cragun for the response.
No, its not a homework, It just came to mind and i was on it.
May be its a silly one and currently its not striking me.
Here are the ones i have tried but its not working.



Code:
D1: grep 'Romeo * Rom ' togrep
D1: grep 'Romeo * Rom' togrep
D1: grep "Romeo * Rom" togrep
D1: grep "Romeo * Rom " togrep

D1: egrep 'Romeo | Rom' togrep
Rom is in Romeo
Romeo is in Rome

D1: grep Romeo togrep | grep Rom
Rom is in Romeo
Romeo is in Rome

Thanks
    #4  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 20 November 2017, 9:27 AM EST
Posts: 1,673
Thanks: 49
Thanked 641 Times in 601 Posts

Code:
 grep Romeo.*Rome gotamp.txt

The Following User Says Thank You to Aia For This Useful Post:
gotamp (05-26-2016)
Sponsored Links
    #5  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
gotamp's Unix or Linux Image
gotamp gotamp is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 December 2016, 11:13 AM EST
Posts: 29
Thanks: 17
Thanked 0 Times in 0 Posts
Many thanks Aia.

now i understood, i was missing the period . before *
Sponsored Links
    #6  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 December 2017, 4:36 AM EST
Location: San Jose, CA, USA
Posts: 10,790
Thanks: 592
Thanked 3,772 Times in 3,220 Posts
For these two lines of input, any of the following will select only the 2nd line:

Code:
grep '^Rome' togrep
grep 'e$' togrep
grep 'o i' togrep

If there is other input that needs to be rejected, or criteria other than just "grep, so that only last line would be the outcome" from the two line input file:

Code:
Rome is in Romeo
Romeo is in Rome

you need to provide much clearer requirements for what you are trying to do.
The Following User Says Thank You to Don Cragun For This Useful Post:
gotamp (05-26-2016)
Sponsored Links
    #7  
Old Unix and Linux 05-26-2016   -   Original Discussion by gotamp
gotamp's Unix or Linux Image
gotamp gotamp is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 17 December 2016, 11:13 AM EST
Posts: 29
Thanks: 17
Thanked 0 Times in 0 Posts
Apologies for not being clear while mentioning my requirement.
yes actually there were number of other inputs as well those were to be rejected.
Anyways thanks for the help !!
Will try to be more clear and precise next time onwards.
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unable to grep the reqd field anurupa777 UNIX for Dummies Questions & Answers 5 07-23-2012 11:01 AM
unable to match grep pattern Jcpratap Shell Programming and Scripting 1 05-28-2012 09:35 AM
unable to grep the running processes. Nagaraja Akkiva Shell Programming and Scripting 1 05-22-2012 05:10 AM
Unable to grep control/non printable characters proactiveaditya Shell Programming and Scripting 11 02-04-2012 12:22 PM
unable to grep the following pattern suri Shell Programming and Scripting 2 03-07-2007 03:03 AM



All times are GMT -4. The time now is 06:45 PM.