user3395315
user3395315

Reputation: 31

How do I pass a variable into AWK FNR?

#!/bin/bash

export num=50
echo $num

awk -v awk_num=$num 'FNR==2, FNR==$awknum {print $1;}' big_report > short_report

I have a big_report file. The desired output is to print rows 2 to 50 in column 1 of big_report into short_report. However, when I run above the result in short_report, includes all lines in column 1 instead of the specified rows 2-50. I would really appreciate it if anyone could help! Thanks!!!

Upvotes: 2

Views: 1150

Answers (1)

jas
jas

Reputation: 10865

Like this:

awk -v awk_num=$num 'FNR==2, FNR==awk_num {print $1}' big_report > short_report

Upvotes: 1

Related Questions