Echo awk output from its variable

Stumped with the formatting of the awk output when used with variables, e.g.:

awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1

produces the desired output (with rows), but when echoing the variable below, the output is one continuous line

var1=$(awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1)
echo $var1

Did i miss something with the awk statement? Please advise and thanks in advance.

echo "$var1"

(otherwise you're passing echo a list of arguments, which it outputs separated by space)

1 Like
var1="$(awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1)"

Why not just IFS="," read -r A B C D E F G < infile

This works by setting

echo "$var1"