在 shell 脚本中从文件中读取随机行的简单方法是什么?
最佳答案
你可以使用shuf
:
shuf -n 1 $FILE
还有一个名为 rl
的实用程序。在 Debian 中,它位于 randomize-lines
包中,它完全符合您的要求,但并非在所有发行版中都可用。在其主页上,它实际上建议使用 shuf
代替(我相信它在创建时并不存在)。 shuf
是 GNU coreutils 的一部分,rl
不是。
rl -c 1 $FILE
https://stackoverflow.com/questions/448005/
相关文章:
linux - 我在哪里可以设置 crontab 将使用的环境变量?
linux - 在 Ubuntu 中创建目录的符号链接(symbolic link)
python - 将 matplotlib 图例移到轴外使其被图形框截断
python - 初始化 dict : curly brace literals {} or the
linux - 如何在不运行 Bash 脚本的情况下对其进行语法检查?
python - 为什么很多例子在 Matplotlib/pyplot/python 中使用 `fi