Re: [ask] awk - passing for loop bash variables to awk
Morning Star [2012-09-16 15:44:05 +0700] wrote:
> I get a difficulty to produce the desired output using awk. i want to
> use for loop bash variable as the input to the awk variable here is
> the illustrated input:
> here is the desired output:
> line_1
> line_2
> line_3
>
> here is what i do:
> cat input | for (( i=1;i<=3;i++ )); do gawk -v var=$i 'NR == var { print}'; done
Maybe not what you are asking for but one can get the desired output
with these:
$ awk 'NR >= 1 && NR <= 3 { print }' inputfile
$ head -n3 inputfile
$ sed -n 1,3p inputfile
Reply to: