grep command problem
1 Attachment(s)
Hi guys!
I have a file called text1.txt which contains: one is not as much as ten! onerous he could be, often one says you can’t be beaten I am running this command to see which lines would be matched: grep ‘^one’ text1.txt | grep ‘ten$’ The problem that I have is the output is different of what I think it should be. My thinking process is grep ‘^one’ text1.txt will display the lines that start with one, so the three lines should be printed. Then, the output will be sent as input to grep ‘ten$’. grep ‘ten$’ will display the lines that end with ten from the input. So the final output should be: one is not as much as ten! onerous he could be, often one says you can’t be beaten But instead I am getting this output from console. onerous he could be, often one says you can't be beaten From you guys that know a lot about Linux, would you please explain this? thank you very much as always! |
The first line ends in a punctuation. ! . And therefor does not end with ten.
|
UPSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS!!!!!!!
I was soooo focus on "ten" that I missed that. Thank you soooo very much for your help! |
If you have GNU grep (or others), you can do that in one move.
Code:
grep -e '^one' -e 'ten$' text1.txt Code:
grep -e '^one' -e 'ten[[:punct:]]*$' text1.txt Code:
man 7 regex |
All times are GMT -5. The time now is 12:25 AM. |