How do I read the first line of a file using cat?

前端 未结 11 955
渐次进展
渐次进展 2021-01-29 22:20

How do I read the first line of a file using cat?

11条回答
  •  你的背包
    2021-01-29 22:31

    You dont need any external command if you have bash v4+

    < file.txt mapfile -n1 && echo ${MAPFILE[0]}
    

    or if you really want cat

    cat file.txt | mapfile -n1 && echo ${MAPFILE[0]}
    

    :)

提交回复
热议问题