-   Linux - General (
-   -   grep issue (

alape 01-28-2012 10:43 AM

grep issue
Hi everyone ^^

file name: test.txt


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


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

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

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.