仅使用Shell脚本从文本文件中获取特定行 [英] Get specific line from text file using just shell script
本文介绍了仅使用Shell脚本从文本文件中获取特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从文本文件中获取特定行.
I am trying to get a specific line from a text file.
到目前为止,在网上我只看到过sed之类的东西(我只能使用sh-不能使用bash或sed或类似的东西).我只需要使用基本的Shell脚本即可完成此操作.
So far, online I have only seen stuff like sed, (I can only use the sh -not bash or sed or anything like that). I need to do this only using a basic shell script.
cat file | while read line
do
#do something
done
我知道如何遍历行,如上所示,但是如果我只需要获取特定行的内容怎么办
I know how to iterate through lines, as shown above, but what if I just need to get the contents of a particular line
推荐答案
sed:
sed '5!d' file
awk:
awk 'NR==5' file
这篇关于仅使用Shell脚本从文本文件中获取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文