[Cialug] lsof! grep?

Jeffrey Ollie jeff at ocjtech.us
Mon Jun 30 18:20:15 CDT 2008


On Sun, Jun 29, 2008 at 9:03 AM, Todd Walton <tdwalton at gmail.com> wrote:
> lsof | awk '{print $9}' | grep \\.so | sort -u
>
> lsof - lists files that are open, one per line, with some extra info.  nifty.
> awk '{print $9}' - snips out the 9th field in the "record"
> sort -u - alphabetizes lines of text, showing duplicate lines only once
> grep \\.so - ???
>
> grep pulls out only the lines matching the pattern.  But I don't get
> what the two backslashes are for.  My output only has lines that
> contain a ".so" in them, but surprisingly some of them contain text
> after the .so.  I would expect grep to show only lines that end in
> .so.  I'm guessing it has something to do with those two backslashes.
> 'man grep' is not helpful.  ( /\\ )

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.

Jeff


More information about the Cialug mailing list