我想将大文本文件(数十 GB)的一部分复制到新的较小文件中,从一定的百分比偏移量开始到结尾,或者从 5% 开始。可以在 Windows 中使用简单的命令来完成吗?
如果你有 Windows 10,你可以使用Ubuntu-Bash cmd,否则你可能想使用Unix-GNU-Utils-for-Windows
安装后,您将能够使用 unixhead和tail命令,并将输出重定向到一个新文件中
head -100 (或任意数量的行)
tail -100 (或任意数量的行)
为了获取文件中的行数,您可以使用 Unixwc -l命令
wc -l filename.txt
Run Code Online (Sandbox Code Playgroud)
获得此文件中的行数后,您可以将数字与 5/100 相乘以获得 5% 的数量,并在headortail命令中使用此结果,例如
head -100000 file1 > file2
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)wc - print newline, word, and byte counts for each file -l, --lines print the newline counts
| 归档时间: |
|
| 查看次数: |
2942 次 |
| 最近记录: |