linux - 仅使用 shell 脚本从文本文件中获取特定行

我正在尝试从文本文件中获取特定行。

到目前为止,我在网上只看到过 sed 之类的东西(我只能使用 sh -not bash 或 sed 或类似的东西)。我只需要使用基本的 shell 脚本来执行此操作。

cat file | while read line
    do
       #do something
    done

我知道如何遍历行,如上所示,但如果我只需要获取特定行的内容怎么办

最佳答案

sed:

sed '5!d' file

awk:

awk 'NR==5' file

https://stackoverflow.com/questions/19327556/

相关文章:

python - 仅在 Django 启动 ONCE 时执行代码?

linux - 使用 bash 为文件添加文件扩展名

python - Python 的 List 是如何实现的?

linux - 如何使用 cURL 从 GitHub 下载 tarball?

linux - 使用 find 命令但排除两个目录中的文件

python - 在 Python 中使用多个参数进行字符串格式化(例如 '%s ... %s' )

python - linux tee 不能与 python 一起使用?

python - 如何在被调用的方法中获取调用者的方法名?

python - 访问对象内存地址

python - 如何在python中打印百分比值?