Bash tool to get nth line from a file

前端 未结 19 2374
刺人心
刺人心 2020-11-22 08:07

Is there a \"canonical\" way of doing that? I\'ve been using head -n | tail -1 which does the trick, but I\'ve been wondering if there\'s a Bash tool that speci

19条回答
  •  [愿得一人]
    2020-11-22 08:59

    To print nth line using sed with a variable as line number:

    a=4
    sed -e $a'q:d' file
    

    Here the '-e' flag is for adding script to command to be executed.

提交回复
热议问题