![](/img/trans.png)
[英]list all files in directory and subdirectories in linux with specific pattern filename
[英]display specific lines in all files in a directory in linux
我的文件夹F中有200个文本文件。我想查看所有文件的2-4行。 我已经尝试过类似的东西:
$sed -n '2,5'p *.txt
但它只读取第一个文件。 有人可以帮忙吗?
此外,我可能需要将这些行发送到新文件,例如:
$sed -n '2,5'p *.txt>path
我对linux的了解是基础知识,因此,如果您有完全不同的解决方案,请更加具体。
awk 'FNR>1&&FNR<5' *.txt > result.txt
这可能对您有用(GNU sed):
sed -ns '2,4p' *.txt > results.txt
如果只想捕获结果:
sed -ns '2,4w results.txt' *.txt
查看和捕获结果的另一种方式:
sed -ns '2,4!b;p;w results.txt' *.txt
有关s
调用选项,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.