Fw: [olug] Unix Tip: GET YOUR IP-ADDRESS (long explanation)

Dr. Aaron M. Segura aaron at robotnet.eu.org
Fri Mar 21 05:08:11 UTC 2003


Well, to be technically correct, it breaks down like this...

echo -e "$( grep -vE '^[[:space:]]*#|^[[:space:]]*$' $1 | wc -l | tr -d 
'[[:space:]]')\t$1"

echo -e "$(number_of_lines_that_aren't_comments_or_blank)\tab\<filename>"

there's no conversion of spaces into tabs.  The 'tr -d' removes any 
blankspace around the number returned by wc, since wc returns the result 
as something like '   23 '.  Then the 'echo -e ' ends with a tab and the 
filename: "\t$1"  The rest of your explanation is good, though, dan.

Oh, vincent!  the purpose of the script was just so that I can say "my 
script is *smaller* than yours".  my script wins!  I will not be denied!

Actually, the real (read:drunken) intentions behind the script were to 
see if I could turn this other little 3 or 4-line script I had into a 
one-line script, and to do it as cryptically as I possibly could, with 
extra points for style.  I got a 'B-minus <see me after class>'.  I'm a 
huge nerd.

<heart>
aaron

> ----- Original Message -----
> From: "Vincent" <vincentr at cox.net>
> To: "Omaha Linux User Group" <olug at olug.org>
> Sent: Thursday, March 20, 2003 6:25 PM
> Subject: Re: [olug] Unix Tip: GET YOUR IP-ADDRESS (long explanation)
>
>
> > The cookie is yours!
> >
> > BTW, This was Rev. Dr. Aaron "The-Script-Monkey" Segura's one-liner. 
>  It counts the lines of actual code in a file just so he can
> > say "my script is bigger than yours".
> > It wouldn't be necessary if wc had an option to ignore blank lines...
> >
> > ----- Original Message -----
> > From: "Daniel Pfile" <daniel at pfile.net>
> > To: "Omaha Linux User Group" <olug at olug.org>
> > Sent: Thursday, March 20, 2003 5:32 PM
> > Subject: Re: [olug] Unix Tip: GET YOUR IP-ADDRESS (long explanation)
> >
> >
> > > Hmm ok... Half to be a smart ass, half to show people just why the
> > > command line is cool... This does explain why that learning the bash
> > > shell book is always near Vince. Please don't nitpick, this is kinda
> > > hard to explain in english, that's why programing languages exist.
> > >
> > > [ $# -gt 0 ]
> > >
> > > If there are more than 0 positional parameters .
> > >
> > > &&  (
> > >
> > > And this works:
> > >
> > > while [ "$1" ];
> > >
> > > Loop through the params
> > >
> > > do ( [ -f $1 ] > > > grep text)" ] ) && ( echo -e "$( grep -vE
> > > > '^[[:space:]]*#|^[[:space:]]*$' $1 | wc -l | tr -d '[[:space:]]'
> > > > )\t$1" ); shift; done ) || echo "Usage: $0 <file> [file file file
> > > > ...]"
> > > >
> > >
> > > Do this if the argument is a file
> > >
> > > && [ "$( file $1 | grep text)" ] )
> > >
> > > The results of running the file command on the argument contains the
> > > word 'text'
> > >
> > > && ( echo -e
> > >
> > > and this echo, grep, wc, tr group of commands work
> > >
> > > "$( grep -vE '^[[:space:]]*#|^[[:space:]]*$' $1
> > >
> > > Print out anything in that file that doesn't either contain a comment:
> > > '^[[:space:]]*# or a blank line: ^[[:space:]]*$
> > >
> > > | wc -l
> > >
> > > Count the number of lines in that output
> > >
> > > | tr -d '[[:space:]]' )\t$1" );
> > >
> > > Convert the output of spaces in wc -l into tabs.
> > >
> > > shift;
> > >
> > > Next please
> > >
> > > done )
> > >
> > > Done with the do.
> > >
> > > || echo "Usage: $0 <file> [file file file...]"
> > >
> > > Since there were less than 0 parameters, show the user the usage 
> of the
> > > script.
> > >
> > > Do I get a cookie Vince?
> > >
> > > -- Daniel
> > >
> > > On Thursday, March 20, 2003, at 04:20 PM, Vincent wrote:
> > >
> > > > Would you provide a long explanation for this one-line script ?  :)
> > > >
> > > > [ $# -gt 0 ] && ( while [ "$1" ]; do ( [ -f $1 ] && [ "$( file $1 |
> > > > grep text)" ] ) && ( echo -e "$( grep -vE
> > > > '^[[:space:]]*#|^[[:space:]]*$' $1 | wc -l | tr -d '[[:space:]]'
> > > > )\t$1" ); shift; done ) || echo "Usage: $0 <file> [file file file
> > > > ...]"
> > > >
> > > >
> > > >
>




More information about the OLUG mailing list