How do I get the last non-empty line of a file using tail in Bash?

前端 未结 7 547
慢半拍i
慢半拍i 2020-12-24 12:26

How do I get the last non-empty line using tail under Bash shell?

For example, my_file.txt looks like this:

hello

7条回答
  •  攒了一身酷
    2020-12-24 13:19

    If tail -r isn't available and you don't have egrep, the following works nicely:

    tac $FILE | grep -m 1 '.'

    As you can see, it's a combination of two of the previous answers.

提交回复
热议问题