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

前端 未结 7 565
慢半拍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:15

    How about using grep to filter out the blank lines first?

    $ cat rjh
    1
    2
    3
    
    
    $ grep "." rjh | tail -1
    3
    

提交回复
热议问题