Hi I want to use gawk in a for loop. Something like this:
for i in gawk {print $1} | tr '\n' ' '
do something using $i
this isn't working of course. Ideas?
Hi I want to use gawk in a for loop. Something like this:
for i in gawk {print $1} | tr '\n' ' '
do something using $i
this isn't working of course. Ideas?
You are missing backquotes or $(...)
to evaluate the awk command.
for i in $(ls -l | gawk '{print $1}' | tr '\n' ' ')
do
echo $i
done
Although the last tr command is not needed since the output from a $(...)
command implicit will have newlines converted to space in this context.
for i in `echo how now | gawk '/how/ { print $2 }'`; do
echo ...$i
done
and
$ sh test.sh
...now
$