[英]display specific lines in all files in a directory in linux
I have 200 text files in folder F. I want to see lines 2-4 of all files. 我的文件夹F中有200个文本文件。我想查看所有文件的2-4行。 I have tried something like:
我已经尝试过类似的东西:
$sed -n '2,5'p *.txt
but it only reads the first file. 但它只读取第一个文件。 Can anybody please help?
有人可以帮忙吗?
Furthermore, I might need to send these lines to a new file, something like: 此外,我可能需要将这些行发送到新文件,例如:
$sed -n '2,5'p *.txt>path
My knowledge of linux is basic, so if you have a totally different solution, please be more specific. 我对linux的了解是基础知识,因此,如果您有完全不同的解决方案,请更加具体。
awk 'FNR>1&&FNR<5' *.txt > result.txt
This might work for you (GNU sed): 这可能对您有用(GNU sed):
sed -ns '2,4p' *.txt > results.txt
If you just want to capture the results: 如果只想捕获结果:
sed -ns '2,4w results.txt' *.txt
Another way to see and capture the results: 查看和捕获结果的另一种方式:
sed -ns '2,4!b;p;w results.txt' *.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.