简体   繁体   English

从多个文本文件中删除前n行和后n行

[英]removing first n and last n lines from multiple text files

I have been stuck for some time now 我被困了一段时间

I have two text files, from which I would like to remove the first two and the last three lines. 我有两个文本文件,我想从中删除前两行和后三行。

So far I have 到目前为止,我有

$tail -n +3 text_1.txt text_2.txt | head -n -3

When I enter this into console, I see that text_2.txt indeed comes out with proper format, but text_1.txt still has that last three lines that need to be removed. 当我将其输入控制台时,我看到text_2.txt确实以正确的格式出现,但是text_1.txt的最后三行仍需要删除。 I presume that head command is not being applied to text_1.txt. 我认为head命令没有应用到text_1.txt。

How can I solve this problem? 我怎么解决这个问题?

for i in text_1.txt text_2.txt; do tail -n +3 "$i" |  head -n -3; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM