如何将N行从一个文件移动到另一个文件

如何将N行从一个文件移动到另一个文件

我想要下载多个文件,所以我决定创建 4 个用脚本处理的文本文件。

toDownload.txt | this file will hold a list of links to download.
inQueue.txt    | the files currently downloading will move here and if failed we can continue later using wget -c flag.
downloaded.txt | this file will hold file links that have finished downloading.
failed.txt     | this file will hold links that failed to start downloading for example if the URL returns 404.

我如何将一个文件中的前 x 个链接移动到另一个文件中?

答案1

#!/bin/sh

lines=3
head -n $lines file1.txt >> file2.txt
sed -i -e "1,$lines d" file1.txt

这会将前三行从 附加file1.txtfile2.txt 然后删除第 1...3 行,从而file1.txt有效地将前三行从 移动file1.txt到 末尾file2.txt

相关内容