Showing results for 
Search instead for 
Do you mean 

exact match

SOLVED
Go to Solution
Highlighted
Honored Contributor [Founder]

exact match

Hi guys,

I'm so tired to even think so can you please advice how can I get the exact string without getting the other similar one?
Get 10 easy points!

# mount|awk '/vghp17uv/'
/uvtmp on /dev/vghp17uvtmp/lvol1 ioerror=mwdisable,largefiles,delaylog,dev=40040001 on Sun Nov 16 01:08:38 2008
/u1 on /dev/vghp17uv/lvol1 ioerror=mwdisable,largefiles,delaylog,dev=40020001 on Sun Nov 16 01:08:39 2008

Here is the problem. It's not getting the right one?
# mount|awk '/vghp17uv/ {print $1}'|cut -d / -f 2
uvtmp
u1
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
8 REPLIES
Acclaimed Contributor [Founder]

Re: exact match

You need to include the "/" in the pattern:
mount | awk '/\/vghp17uv\// {print substr($1,2)}'

If you are using awk, don't need cut.
Honored Contributor [Founder]

Re: exact match

Bang on! Just to note - even though it looks like 'V' (capital 'v'), it is actually, '\' followed by '/'
Honored Contributor [Founder]

Re: exact match


in PERL the Regular expressions have this nice \b to match on a word boundary.

The solution then becomes...

mount | perl -ne 'print $1 if /^.(\w+)\s.*\bvghp17uv\b/'


fwiw,
Hein.


Acclaimed Contributor [Founder]

Re: exact match

Hi:

You could also use Perl which allows a variety of delimiters for regular expressions and makes using the '/' character simple to visualize.

# mount|perl -nale 'print $F[0] if $F[2]=~m{/vghp17uv/}'
/u1

This also avoids having to worry about the length of fields. Notice that Perl numbers the first field as zero whereas 'awk' counts from one.

Regards!

...JRF...
Valued Contributor [Founder]

Re: exact match

If you're searching with regexps you need to delimit your search... vghp17uv is in both vghp17uv and vghp17uvtmp.

mount | egrep "/vghp17uv/" | cut -d'/' -f2

this should work better (since egrep doesn't bother with that // to specify a search) and give you a more exact match.

Best regards
Fredrik Eriksson
Acclaimed Contributor [Founder]

Re: exact match

>Fredrik: since egrep doesn't bother

There is no reason to use the egrep hammer, fgrep/grep is fine. You can also use grep -w and leave out the "/".
Valued Contributor [Founder]

Re: exact match

True, seems like I was abit tired to when i wrote it :P
grep would do it fine since no regexp is involved :P
Honored Contributor [Founder]

Re: exact match

Closed
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003