![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to find file name for non matching pattern | sujoy101 | Shell Programming and Scripting | 5 | 03-31-2008 09:10 AM |
| perl - how do i find out if a file doesn't contain a pattern? | mjays | Shell Programming and Scripting | 4 | 09-19-2007 06:28 AM |
| find and replace a pattern in a file | krishnamaraju | Shell Programming and Scripting | 1 | 08-29-2006 10:02 AM |
| How to find out the exact year in "Last modified time" using ls command | Dophlinne | UNIX for Dummies Questions & Answers | 6 | 04-11-2006 11:07 AM |
| Find script with input pattern file | iguanathompson | Shell Programming and Scripting | 8 | 02-06-2006 06:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to find the exact pattern from a file?
Hi
Let say there is a file a.txt which contain number rows. My intention is to find the number of occurences of a pattern. Let say the pattern is mdbase. then it should not count the occurences of mdbase1 or mdbase2 like this. When I tried to find it like grep "/backup/surjya/mdbase" xmldir.conf_backup | wc -w The out put is 3 rather than 1. So please let me know how it can be resolved Thanks |
|
||||
|
I tried like below:
dir2=\"$dir1"\>"\" echo $dir2 stgdircount=`grep $dir2 xmldir.conf | wc -w | awk '{print $1}'` echo $stgdircount let say dir1=/backup/surjya/mdbase. hence the output for dir2 is "/backup/surjya/mdbase\>" and for stgdircount is 0, but exactly there is two entries in this file. Please give me some idea. |
|
|||||
|
In the grep statment you gave, it is searching for
"/backup/surjya/mdbase\>" I am sure you want to search for /backup/surjya/mdbase and not the above statement. Look at this Code:
sh-2.05b$ cat surya.txt /backup/surjya/mdbasewed /backup/surjya/mdbase2 /backup/surjya/mdbase /backup/surjya/mdbase3 /backup/surjya/mdbase sh-2.05b$ grep -c "/backup/surjya/mdbase\>" surya.txt 2 sh-2.05b$ grep -c "/backup/surjya/mdbase" surya.txt 5 |
|
||||
|
yes you are right but why it gives 0 when I try to execute it through shell script. Let say the script is
dir1=/backup/surjya/mdbase stgcnt=`grep -c $dir1 surya.txt ` echo $stgcnt The value of stgcnt is 5. Just modify the script like dir1=/backup/surjya/mdbase stgcnt=`grep -c \"$dir1"\>"\" surya.txt ` echo $stgcnt The value of stgcnt is 0 I hope my question is clear. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|