![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to grep for a word and display only the word | ananthmm | UNIX for Dummies Questions & Answers | 6 | 05-29-2008 05:00 AM |
| grep for "exact word" | bullz26 | Shell Programming and Scripting | 7 | 03-14-2008 02:00 AM |
| Exact Match thru grep ????? | manas_ranjan | UNIX for Advanced & Expert Users | 2 | 08-17-2007 02:57 AM |
| How to grep the exact name? | csaha | Shell Programming and Scripting | 3 | 01-31-2006 08:47 AM |
| grep - exact | wxornot | UNIX for Dummies Questions & Answers | 9 | 01-02-2006 11:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I have a quary regarding grep command in linux. I have a file which contains 56677 56677 +56677 +56677 56677 56677 56677 I want to extract total count of "56677" When I hit the following command #cat filename | grep -w -c '56677' the result comes 7. Its counting including "+56677". I need count of only "56677" . Is there any option of grep to extract count of only "56677" excluding count of "+56677". Please provide the command ASAP. Waiting for the response ... Thanks in advance .. Maddy |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
check if -w option is enabled on your system
Check if you can use -w option in the grep. This would depend on what system you are using.
Sometimes exact word can be searched as putting the value in angled brackets. grep "\<VALUE\>" |
|
#3
|
|||
|
|||
|
I don't think there is an option in grep itself to fiddle with the semantics of the -w option. Some locales probably have slightly different definition of what constitutes a "word" but relying on that seems brittle at best. Perhaps it's simplest to explicitly specify what characters are allowed as word separators. Something like this, maybe?
Code:
egrep -c '(^|[ ])56677([ ]|$)' filename Note also that you don't need or want the cat there; grep can read what input files you want to feed it all by itself. |
|
#4
|
||||
|
||||
|
why not use the 'tag' to work from the beginning of the line?
Two examples: Code:
> grep -c "^56677" <sample 5 > cat sample | grep -c "^56677" 5 |
||||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|