![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| 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 08:00 AM |
| grep for "exact word" | bullz26 | Shell Programming and Scripting | 7 | 03-14-2008 05:00 AM |
| Exact Match thru grep ????? | manas_ranjan | UNIX for Advanced & Expert Users | 2 | 08-17-2007 05:57 AM |
| How to grep the exact name? | csaha | Shell Programming and Scripting | 3 | 01-31-2006 11:47 AM |
| grep - exact | wxornot | UNIX for Dummies Questions & Answers | 9 | 01-02-2006 02:03 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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\>" |
|
||||
|
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. |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|