bash - 删除空行后从文本文件中选择随机行
问题描述
解决方案
Where does the output of your first sed command go? Based on what you have, it goes to stdout. It is definitely going to stdout within the $(...) sub-process. This means they are written straight out to the outer sub-process as command line arguments.
The shuf command is trying to get something from stdin, not arguments from the command line.
What might work (I have not tried this), is to pipe. Try this
sed '/^\s*$/d' input.txt | shuf -n 1 >output.txt
Hope this helps
推荐阅读
- javascript - 如何在适用于 JS 的 Google Analytics Embed API 中捕获错误
- java - 如何在 JTextField 的开头输入文本
- java - 如何在项目中保存多个位置坐标?
- typescript - 打字稿:映射类型以使每个属性只读,除了选定的属性
- pointers - 使用reflect.New时如何设置标签
- mysql - 在mysql中创建一个报告并将其存储在一个日志文件中,使用触发器,然后分析日志
- typescript - 更改 TypeScript 代码的目标版本会导致 TypeScript 编译器不再找到该模块
- javascript - 一个对象中的多个“异步获取器”充当缓存
- angular - 如何动态显示另一个内部的组件?
- python - 从三角形多边形中获取最大中位数的有效方法