[lug] bash - awk - command substitution - for loop
karl horlen
horlenkarl at yahoo.com
Tue Nov 6 20:04:51 MST 2007
I'm sure this is a simple question but I've been
searching for the last 3 hours and can't solve it.
I'm trying to feed the output of awk to a for loop.
The problem is that if the output of awk contains
multiple fields separated by any whitespace, the
variable i will be set for each and every field and
not the entire record.
As a bogus example:
for i in $( awk '{print $0}' access_log | sort)
do
echo $i "
done
Each field of the given record is printed on a new
line. I want all the fields for a given record to
passed to $i as one long string.
If i use echo -n it concatentates all variable i's for
all records into one massive long string. No good.
I've tried wrapping the command substitution in quotes
as well:
for i in "`awk '{print $0}' access_log | sort `"
do
echo $i "
done
And i get one huge variable again. No good. If I
take out the quotes, I'm back to each field being on a
separate line.
Hopefully you can follow here. How do I preserve
white space within each record output generated by awk
in the command substitution?
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the LUG
mailing list