Bash tool to get nth line from a file

前端 未结 19 2574
刺人心
刺人心 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 09:06

    Using what others mentioned, I wanted this to be a quick & dandy function in my bash shell.

    Create a file: ~/.functions

    Add to it the contents:

    getline() { line=$1 sed $line'q;d' $2 }

    Then add this to your ~/.bash_profile:

    source ~/.functions

    Now when you open a new bash window, you can just call the function as so:

    getline 441 myfile.txt

提交回复
热议问题