Unable to grep

I have a file with 2 lines of code

Rome is in Romeo
Romeo is in Rome

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

Romeo is in Rome

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

Please help.

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?

1 Like

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.

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

 grep Romeo.*Rome gotamp.txt
1 Like

Many thanks Aia.

now i understood, i was missing the period . before *

For these two lines of input, any of the following will select only the 2nd line:

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:

Rome is in Romeo
Romeo is in Rome

you need to provide much clearer requirements for what you are trying to do.

1 Like

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.