Get specific line from text file using just shell script

前端 未结 10 2172
清酒与你
清酒与你 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:42

    I didn't particularly like any of the answers.

    Here is how I did it.

    # Convert the file into an array of strings
    lines=(`cat "foo.txt"`)
    
    # Print out the lines via array index
    echo "${lines[0]}"
    echo "${lines[1]}"
    echo "${lines[5]}"
    

提交回复
热议问题