Issue
Can anyone help with a similar issue? I intend to print specific rows of a column using awk in for loop. I used similar codes as suggested here but could not get any output. I have read href="https://stackoverflow.com/questions/35811546/using-bash-for-loop-variable-within-awk-print">this post but I just did not get any output. I cannot figure it out.
# my input file: sfs_file.new.txt
57 6546 492 3844 1685 4234 2959 6586 5810 4187
63 6658 525 3955 1637 4356 3039 6562 5878 4086
65 6523 495 3978 1663 4310 2960 6515 5708 4235
71 6522 507 3915 1597 4282 2948 6719 5746 4172
58 6593 518 3965 1690 4213 2940 6527 5697 4144
# expected result:
65
71
58
# My codes as below
for i in {3..5};do
awk -F " " -v var=$i 'FNR==var {ptint $1}' sfs_file.new.txt
done
Solution
other alternatives...
$ sed -n '3,5s/ .*//p' file
or
$ awk 'NR==3,NR==5{print $1}' file
Answered By - karakfa Answer Checked By - Willingham (WPSolving Volunteer)