Get specific line from text file using just shell script

前端 未结 10 2169
清酒与你
清酒与你 2020-12-22 16:59

I am trying to get a specific line from a text file.

So far, online I have only seen stuff like sed, (I can only use the sh -not bash or sed or anything like that).

10条回答
  •  悲&欢浪女
    2020-12-22 17:28

    Best performance method

    sed '5q;d' file
    

    Because sed stops reading any lines after the 5th one

    Update experiment from Mr. Roger Dueck

    I installed wcanadian-insane (6.6MB) and compared sed -n 1p /usr/share/dict/words and sed '1q;d' /usr/share/dict/words using the time command; the first took 0.043s, the second only 0.002s, so using 'q' is definitely a performance improvement!

提交回复
热议问题