LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-28-2012, 10:43 AM   #1
alape
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
Unhappy 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
 
Old 01-28-2012, 10:55 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 01-28-2012, 11:49 AM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] tail and grep issue Wim Sturkenboom Linux - General 6 02-06-2008 07:19 AM
grep issue with SuSE 9 vm_devadas SUSE / openSUSE 6 01-24-2007 09:48 AM
Grep parsing issue selfsck Linux - General 3 07-11-2004 08:38 PM
Shell grep issue philipz Programming 8 05-05-2004 01:50 PM
grep -v issue lleemon Linux - General 7 06-16-2003 03:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration