I would like to copy part of huge text file (tens of GB) into new smaller file, starting from the certain offset in percentage to the end, or from beginning 5%. Can that be done with a simple command in Windows?
2 Answers
If you have Windows 10, you can use Ubuntu-Bash cmd otherwise you might want to use Unix-GNU-Utils-for-Windows
Once you'll install it, you'll be able to use unix head and tail commands, and redirect the output into a new file
head -100(or any number of lines)tail -100(or any number of lines)
In order to get the amount of lines in the file, you can use Unix wc -l command
wc -l filename.txt
After you get the number of lines in this file, you can multiple the number with 5/100 in order to get the amount of 5%, and use this result in the head or tail commands
e.g.
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 - print newline, word, and byte counts for each file -l, --lines print the newline counts
- 754
Really easy way - use more and redirect the output:
giantfile.csv- your existing huge filesmallfile.csv- new "small" file you're creating
Type in and hit enter:
more giantfile.csv > smallfile.csv
Hit the Space a couple of times to get some output redirected to the new small file. Then hit Ctrl + Pause to exit the more command. Once you do that, you'll have a new small file with the top of the exiting file in it.
- 12,350
- 11