如何将部分大文件复制到新文件?


2

我想将部分大文本文件(数十GB)复制到新的较小文件中,从百分比到结束的某个偏移量开始,或者从5%开始。可以在Windows中使用简单的命令完成吗?

Answers:


3

如果您使用的是Windows 10,则可以使用 Ubuntu-Bash cmd 否则你可能想用 Unix的GNU-utils的换视窗

一旦你安装它,你将能够使用unix headtail 命令,并将输出重定向到新文件

  • head -100 (或任意数量的行)

  • tail -100 (或任意数量的行)

为了获得文件中的行数,您可以使用Unix wc -l 命令

wc -l filename.txt

获得此文件中的行数后,您可以使用5/100将该数字加倍,以获得5%的数量,并将此结果用于 head 要么 tail 命令 例如

head -100000 file1 > file2

男子头

head - output the first part of files
-n, --lines=[-]K 
print the first K lines instead of the first 10; with the leading '-', print all but the last K lines of each file

男人的尾巴

tail - output the last part of files 
-n, --lines=K
    output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth

wc男人

wc - print newline, word, and byte counts for each file 
-l, --lines
    print the newline counts

有没有办法指定百分比?
Pablo

@pablo - 你可以使用 wc -l 获取巨大文件的长度,并使用num-of-lines *(5/100)计算百分比
Yaron

@Yaron只有当所有线都长度相同时才会准确...
DavidPostill
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.