xyz*_*xyz 2 unix shell bash unix-shell
在 Unix shell 中,如何通过行号从文本文件中选择一行?
假设我希望将animals.txt 中第3 行的任何内容写入标准输出(bat bat bat)。
monkey monkey monkey
cat cat cat
bat bat bat
horse horse horse
Run Code Online (Sandbox Code Playgroud)
有没有标准的程序或简单的方法来做到这一点?
(还有一种情况是文本文件没有包含足够的行来包含您要求的行号)
这是一种方式:
sed -n '3p' file
Run Code Online (Sandbox Code Playgroud)
这是另一个:
head -n 3 file | tail -n 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4620 次 |
| 最近记录: |