A quick & dirty [tag:bash] solution : file=file.txt c=1 while read a; do var=$(cut -d, -f$c $file | paste -sd ',') echo $var ((c++)) done < "$file"