It is usually simpler and more efficient to do both iterating and processing in AWK rather than trying to divide the task by iterating in the shell and processing in AWK. AWK is well designed for iterating through input, and it also has its own loop structures (e.g. for). If at all possible, do all your processing in AWK.
That said, it seems that your problem also requires access to the input fields in the shell, and so full processing in AWK may not be possible in your case. (It is worth noting that AWK can also execute shell commands, but this may be just another level of complication.)
Other answers use AWK to iterate through the file and print something with columns 2 and 4, like
$ awk '{print "My friend", $2, "lives in", $4}' MyFile
which is fine if you can iterate and process with AWK like this. As an addition to this type of solution, you might want to skip the first line (which seems to have column headers instead of actual data) with
$ awk 'NR>1{print "My friend", $2, "lives in", $4}' MyFile
Your comment
In fact my treatment is a little bit more complicated than a print. I need to make some tests and assignments in the "for" loop.
suggests that what you really want is access to the fields in your shell. You can get this by using AWK to pick out the fields (as before), but piping the values into the shell:
awk 'NR>1{print $2,$4}' MyFile | while read user livesIn; do
echo "My friend $user lives in $livesIn"
done
This gives you $user and $livesIn in the shell, and so you can do more complicated shell processing with it. For example:
awk 'NR>1{print $2,$4}' MyFile | while read user livesIn; do
if [[ "$user" == "John" ]]; then
echo "$user is not my friend, but lives in $livesIn"
else
echo "My friend $user lives in $livesIn"
echo "$user" >> friends.txt
fi
done
Be careful with the format of your input file since AWK is splitting on white space.
print $2 $4will not separate the fields with a space. You want eitherprint $2, $4(which uses the OFS implicitly) or explicitlyprint $2 " " $4