Re: exact match (581 Views)
Reply
Honored Contributor
Posts: 2,116
Registered: ‎09-26-2002
Message 1 of 9 (581 Views)
Accepted Solution

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
Acclaimed Contributor
Posts: 26,109
Registered: ‎03-06-2006
Message 2 of 9 (581 Views)

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
Posts: 1,096
Registered: ‎09-12-2004
Message 3 of 9 (581 Views)

Re: exact match

Bang on! Just to note - even though it looks like 'V' (capital 'v'), it is actually, '\' followed by '/'
Honored Contributor
Posts: 6,593
Registered: ‎05-19-2003
Message 4 of 9 (581 Views)

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
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 9 (581 Views)

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
Posts: 237
Registered: ‎09-01-2008
Message 6 of 9 (581 Views)

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
Posts: 26,109
Registered: ‎03-06-2006
Message 7 of 9 (581 Views)

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
Posts: 237
Registered: ‎09-01-2008
Message 8 of 9 (581 Views)

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
Highlighted
Honored Contributor
Posts: 2,116
Registered: ‎09-26-2002
Message 9 of 9 (581 Views)

Re: exact match

Closed
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.