bash command to print column at specific range of line numbers

前端 未结 3 1612
独厮守ぢ
独厮守ぢ 2020-12-22 02:20

I\'m trying to get the values in column X at lines 5 to 5 + Y. I\'m guessing there\'s a quick way to do this with awk. How is this done?

3条回答
  •  梦毁少年i
    2020-12-22 03:03

    I think this will work for you, untested:

    awk 'NR >= 5 && NR <= 5 + Y { print $X }' file.txt
    

    Obviously, substitute X and Y for some real values.

    EDIT:

    If X and Y are shell variables:

    awk -v column="$X" -v range="$Y" 'NR >= 5 && NR <= 5 + range { print $column }' file.txt
    

提交回复
热议问题