echo cat:cat Records.txtecho ""echo Using a digit for the second record:record_id=$(awk 'NR==2{print $1; exit}' Records.txt)echo $record_idecho ""a=2echo a is set to $aecho ""echo Using a variable and single quotes:record_id=$(awk 'NR==$a{print $1; exit}' Records.txt)echo $record_idecho Using a variable and double quotes:record_id=$(awk "NR==$a{print $1; exit}" Records.txt)echo $record_id
Output
cat:Apples 1000 happy wormsCarrots 10 happy bunniesUsing a digit for the second record:Carrotsa is set to 2Using a variable and single quotes:Using a variable and double quotes:Carrots 10 happy bunnies
I understand that double quotes are needed to use a variable, but why is it nolonger confined to output of the first field only? I only want the word Carrots.