If you just want to refer to those fields by their names instead of numbers, you can use read:
while read id name age
do
echo "$id $age"
done < file.tsv
EDIT
I saw your meaning at last! Here's a bash function that will print out only the columns you specify on the command line (by name).
printColumns ()
{
read names
while read $names; do
for col in $*
do
eval "printf '%s ' \$$col"
done
echo
done
}
Here's how you can use it with the file you've presented:
$ < file.tsv printColumns id name
1 ed
2 joe
(The function reads stdin. < file.tsv printColumns ... is equivalent of printColumns ... < file.tsv and cat file.tsv | printColumns ...)
$ < file.tsv printColumns name age
ed 50
joe 70
$ < file.tsv printColumns name age id name name name
ed 50 1 ed ed ed
joe 70 2 joe joe joe
Note: Pay attention to the names of the columns you request! This version lacks sanity checks, so nasty things can happen if one of the arguments is something like "anything; rm /my/precious/file"
catisn't necessary, BTW. You could useawk '{ print $1, $3 }' file.tsv– Eric Wilson Nov 22 '11 at 16:58idinstead of$1andageinstead of$3– Michael Mrozek♦ Nov 22 '11 at 17:25