有没有办法从文件底部读取直到找到某个字符

Is there a way to read from the bottom of a file until a certain character is found

我正在处理一个非常大的文件,我需要访问底部的最后几个条目,所以使用 tail 会很好,但问题是每次读取的行数都会发生变化。但是,我知道当发现新行字符时我需要停止,所以我想知道是否有办法做到这一点?

感谢任何帮助。谢谢。

tac 是你的朋友它是 cat 反过来

tac yourfile|while read LINE; do if [[ -z "$LINE" ]] ;  then break; fi; echo $LINE; done

这会反向读取文件并在第一个空行处停止