[lug] bash - awk - command substitution - for loop

Jeffrey Haemer jeffrey.haemer at gmail.com
Wed Nov 7 06:20:29 MST 2007


"for" and the shell are the problem, not awk.

The "for" is just looping through the white-space-separated tokens and
assigning them to $i.
The "read" is reading a line at a time and assigning it to $i.

awk '{print $0}' is just "cat", so the example that worked, below, can be
more easily written as

    sort access_log | while read i

but the original was probably complicated and you were just simplifying it
to try to figure out what the heck was going wrong.

You could use the original approach by arranging to have awk print the lines
surrounded by single quotes, but that way lies quote-escaping hell.
Repent.  Use "while read i"

Hope this helps.




On Nov 7, 2007 12:32 AM, karl horlen <horlenkarl at yahoo.com> wrote:

> > However, the one thing you might want to try is to
> > rearrange the loop:
> >
> > awk '{print $0}' access_log  | sort | while read i
> > do
> > echo $i
> > done
>
> Not sure why that makes a difference but it worked
> like a charm! Thanks.
>
> If anybody knows how to eliminate the spaces from my
> command substitution example, I'd still like to know
> how or why it doesn't work.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>



-- 
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell]
http://goyishekop.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20071107/e2f181f2/attachment.html>


More information about the LUG mailing list