Bash tool to get nth line from a file

前端 未结 19 2510
刺人心
刺人心 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:45

    If you got multiple lines by delimited by \n (normally new line). You can use 'cut' as well:

    echo "$data" | cut -f2 -d$'\n'
    

    You will get the 2nd line from the file. -f3 gives you the 3rd line.

提交回复
热议问题