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

标签 linux unix

我现在已经卡住了一段时间了

我有两个文本文件,我想从中删除前两行和最后三行。

目前为止

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

当我将其输入控制台时,我看到 text_2.txt 确实以正确的格式输出,但 text_1.txt 仍然有最后三行需要删除。我假设 head 命令未应用于 text_1.txt。

我该如何解决这个问题?

最佳答案

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

关于linux - 从多个文本文件中删除前 n 行和后 n 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56557286/

相关文章:

linux - 在 shell 脚本中与非 root 用户连接后更改 root

linux - yum 可以告诉我哪些存储库提供了特定的包吗?

c++ - 释放锁定的内存是否会解锁相应的页面?

bash - 在 Bash 中递增数字并添加前导零

linux - 学习网络编程有哪些好的资源?

linux - 如何仅显示 wget 进度条?

linux - 在函数中重定向 stderr

python - 在 Linux 上使用 discord.py 我得到错误 'Bot' object has no attribute 'join_voice_channel'

linux - ls 在目录中获取文件列表

linux - Rsync with --checksum 从本地到本地?