Fedora Linux Support Community & Resources Center
  #1  
Old 10th September 2009, 04:07 PM
xtcsin Offline
Registered User
 
Join Date: Aug 2008
Posts: 16
linuxfedorafirefox
The problem of grep command, i want to know how the expression match the result

I have a file named a.txt, and its content is as follows:
Quote:
sdjksdj ksfjs ksj skjf sjf
ls afkfs
sfksj fjskddddddddddjfskdjfsjdkf ksj fks
I run shell command : cat a.txt |grep "fs*"
the result is all the three lines, why?

I run cat a.txt |grep -o "fs*" and the result is as follows:
f
f
f
f
fs
f
f
fs
fs
f
f


I want to know how "fs*" match the result. Thanks.
Reply With Quote
  #2  
Old 10th September 2009, 04:26 PM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
linuxfedorafirefox
try the option "--color=auto". You'll see for yourself Usually grep put the whole line containing a match to the output, but the -o switch tells it to print only the matched parts one by one, each on its own separate line.

By the way, don't put patterns in double quotes. You shell will try to expand it before passing it to grep.

For example, if you have a file named "fsA" in the working directory, "fs*" will be expanded as "fsA", and grep will use this pattern (an exact match) instead of the intended "fs*" (f followed by zero or more 's' characters).
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.

Last edited by aleph; 10th September 2009 at 04:40 PM.
Reply With Quote
Reply

Tags
command, expression, grep, match, problem, result

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
rename command with regular expression amranny Using Fedora 8 26th September 2008 07:52 AM
problem w/ "sudo lsusb -v | grep -i Serial" command vitasoy Using Fedora 2 14th September 2008 06:07 PM
Networking - unknown problem, result = no network... RBG79_Eire Using Fedora 1 12th June 2007 11:03 PM
Help constructing a grep command KhaiPi Using Fedora 5 30th January 2007 01:48 AM
help me about the command of grep Stevenisme Using Fedora 7 3rd September 2005 10:56 AM


Current GMT-time: 03:52 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat