LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep issue (https://www.linuxquestions.org/questions/linux-general-1/grep-issue-926182/)

alape 01-28-2012 10:43 AM

grep issue
 
Hi everyone ^^

file name: test.txt

koki:45
kiki:15
lulu:touki

I want grep to return me all words with "ki" before ":"
- koki
- kiki

No touki because it's after ":"

When i do "grep ki test.txt" I got the 3. :(

I need your help. Thanks

druuna 01-28-2012 10:55 AM

Hi,

This all words with "ki" before ":" can still mean 2 things:
- ki immediately followed by :
Code:

grep "ki:" test.txt
- ki anywhere as long as it is before :
Code:

grep "ki.*:" test.txt
The .* translates to any character.

Hope thi helps.

anomie 01-28-2012 11:49 AM

druuna is exactly correct, but I'd just tack on a quick note:
  • . == matches any single character
  • * == matches zero or more instances of the previous item

When combined, the expression '.*' means (read from right to left, due to the operator's effect) match zero or more occurrences of any character.


All times are GMT -5. The time now is 10:10 AM.