home Mail List
Info
Info
Meetings
Goals
Upcoming
Projects
FAQ
Security
Links

[Date Prev][Date Next] [Chronological] [Thread] [Top]

[NMLUG] grep help



From: "Jason Davis" <jason@claim.md>
Sent: Wednesday, March 16, 2005 6:58 PM


>> > this works for me
>> >
>> > if grep "audio.*,*fred,*" /etc/group > /dev/null; then echo "yes"; fi
>> >
>> > here is the line from /etc/group
>> > audio:x:29:mohadib,fred
>>
>>   Unfortunately, that would also succeed for
>> kaudiod:x:129:mohadib,freddy
>
> oh , good point :) guess you could throw a ^ at the start


  That is why my original regexp was, using your example group and user, 
"^audio:.*[:,]fred[,$]".  That should match your audio line.  Must start at 
the beginning of the line and the audio must end in a colon, since a colon 
is the field delimeter and illegal in a group name.  The .* for I don't care 
what comes next.  The [:,]fred[,$] to mean there can either be a colon of a 
comma then the user name finished with a comma or end of line.  The point is 
to be as specific as possible.

  The problem is that grep wasn't successfully matching when the user was at 
the end of the line.  If I use 2 grep commands, I can make it work.

  if grep "^audio:.*[:,]fred," /etc/group || grep "^audio:.*[:,]fred$" 
/etc/group ; then echo yes ; fi

  succeeds with each of the following lines:
audio:x:29:fred
audio:x:29:fred,bob
audio:x:29:mohadib,fred
audio:x:29:mohadib,fred,bob





Please send sugestions and comments to webmaster@nmlug.org.
Valid XHTML 1.1! Valid CSS! Powered by Debian Powered by Apache