coreutils:打印文件中的第 n 行,阻塞直到它存在

coreutils: print nth line in file, block until it exists

如何打印文件或输入的第 n 行,并阻塞直到它存在?我想坚持使用 coreutils。

sed 'NUMq;d' file 会很快给我第 n 行,但不会阻塞。

tail -f file 会阻止,但不会做其他事情。

我应该能够将该行通过管道传输到其他内容,例如使用文件:

<block-until-line-20-exists> file | <process-line>

或者,输入:

tail -n 0 -f file | <block-until-line-20-exists> | <process-line>

没关系。我想我回答了我自己的问题。 tail & sed 毕竟是解决方案。

tail -n 0 -f file | sed '20q;d'

原来 tailsed 完成后停止阻塞。

编辑:根据您的使用方式,可能会出现 time-of-check/time-of-use 错误。