gpt4 book ai didi

unix - 使用 Unix shell 命令将前 1000 行从文本文件移动到新文件

转载 作者:行者123 更新时间:2023-12-03 01:25:39 26 4
gpt4 key购买 nike

我希望将包含超过 5000 万个条目的文本文件中的前 1000 行复制到另一个新文件,并从原始文件中删除这些行。

是否有某种方法可以在 Unix 中使用单个 shell 命令执行相同的操作?

最佳答案

head -1000 input > output && sed -i '1,+999d' input

例如:

$ cat input 
1
2
3
4
5
6
$ head -3 input > output && sed -i '1,+2d' input
$ cat input
4
5
6
$ cat output
1
2
3

关于unix - 使用 Unix shell 命令将前 1000 行从文本文件移动到新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/801004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com