Hi everyone,
I want to split a text file into two or more parts, or delete certain lines. I have these huge text files, some of which are around 400k lines. I want to split the file into multiple parts to create two (or more) separate files of equal size, or just delete all lines from the 200k-400k rows. I just downloaded textpad, so I'm a complete newbie.
Thanks in advance!
split a text file into two or more parts
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: split a text file into two or more parts
- Press Ctrl+G (or use the menu "Search > Go To...").
- Make sure the radiobutton "Line" is chosen, then enter "200000" as value, because that's the line (or "row") you want to go to. Press button "Go To".
- Press Shift+Ctrl+End, so you select all text (Shift) from that position to the end of the document (Ctrl+End).
- Press Del (or use the menu "Edit > Delete > Selection").
- Ctrl+Home = start of document
- Ctrl+End = end of document
- Shift+Right/Left/Up/Down = extend current selection per character/line
- Ctrl+Shift+Right/Left/Up/Down = extend current selection per word/paragraph
- Ctrl+Right/Left/Up/Down = go to next word/paragraph (instead of just next character/line with arrow keys only)
- Ctrl+A = select everything (whole document)
- Ctrl+Z = undo last operation
- Ctrl+F = (quickly) find
- F3 = find next
To "split" one document in many I would use a very similar approach:
- Press Ctrl+G (or use the menu "Search > Go To...").
- Make sure the radiobutton "Line" is chosen, then enter "200000" as value, because that's the line (or "row") you want to go to. Press button "Go To".
- Press Shift+Ctrl+Home, so you select all text (Shift) from that position to the start of the document (Ctrl+Home).
- Press Ctrl+X (or use the menu "Edit > Cut") to move all those lines into the clipboard.
- Press Ctrl+N (or use the menu "File > New") to create a new document.
- Press Ctrl+V (or use the menu "Edit > Paste") to copy all lines from the clipboard into the new document (the clipboard remains filled).
- (optional) Press Ctrl+S (or use the menu "File > Save") to store the new document under a given filename.
- Press Ctrl+F4 (or use the menu "File > Close") to close the saved document. If you left out the previous step you're now being asked if you want to save your document to a file first.
- Repeat from step #1 until your original files becomes empty. Then it's up to you if you want to save the changes to that or not.
Re: split a text file into two or more parts
There are various ways of splitting a file using PowerShell described here:
https://powershellfaqs.com/split-large- ... owershell/
https://stackoverflow.com/questions/100 ... powershell
Having said that, the script below runs mind-numbingly slowly, so AmigoJack's solution has much to recommend it!
Note that TextPad's GoTo command accepts a relative line number, so from the first line, you could repeatedly goto line +1000 with the Extend Selection option checked, use the Save As command to save the selected text, then press the Esc key to clear the selection.
https://powershellfaqs.com/split-large- ... owershell/
https://stackoverflow.com/questions/100 ... powershell
Having said that, the script below runs mind-numbingly slowly, so AmigoJack's solution has much to recommend it!
Code: Select all
# Script to split a file by line count
# Usage: powershell.exe -file splitfile.ps1 BIGFILE 1000
# Based on example at https://powershellfaqs.com/split-large-text-files-with-powershell/
$sourceFile = $args[0]
$lineCount = $args[1] # The number of lines each split file should contain
$counter = 1
Get-Content $sourceFile | ForEach-Object {
$fileName = $sourceFile + $counter.ToString("000")
Add-Content -Value $_ -Path $fileName
if ((Get-Content -Path $fileName).Count -ge $lineCount) {
$counter++
}
}