[Cialug] lsof! grep?
Jeff Chapin
chapinjeff at gmail.com
Tue Jul 1 10:45:32 CDT 2008
I tend to single quote and avoid the multiple '\' issue all together.
The single quotes eliminate the escaping need for bash.
To add a fun little regex trick, to match '.so' at the end of a word,
and not midword (foo.soblah) or end of a line (.so$ from earlier) grep
supports word boundry tokens (/b) so you can do the following:
$ echo aso|grep '\.so\b'
$
$ echo .so|grep '\.so\b'
.so
$
$ echo .sobar|grep '\.so\b'
$
$ echo .sobar blah blah|grep '\.so\b'
$
$ echo .sobar blah blah .so blah|grep '\.so\b'
.sobar blah blah .so blah
YMMV
Jeff
Jeffrey Ollie wrote:
> On Tue, Jul 1, 2008 at 10:30 AM, Todd Walton <tdwalton at gmail.com> wrote:
>
>> On Mon, Jun 30, 2008 at 6:20 PM, Jeffrey Ollie <jeff at ocjtech.us> wrote:
>>
>>> On Sun, Jun 29, 2008 at 9:03 AM, Todd Walton <tdwalton at gmail.com> wrote:
>>>
>>>> lsof | awk '{print $9}' | grep \\.so | sort -u
>>>>
>>> Grep uses regular expressions to match lines. A period in a regular
>>> expression means "match any character". A backslash in front of the
>>> period tells grep to not give the period any special meaning and to
>>> match just a period. The second backslash in front of the other
>>> backslash escapes the backslash for the shell.
>>>
>> Oh. So could I accomplish the same thing with:
>> grep ".so"
>>
>
> No, because that would match "Aso", "Bso", etc:
>
> $ echo "Aso" | grep ".so"
> Aso
>
> Jeff
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
More information about the Cialug
mailing list