I am trying to split a text file based on several strings into two files using Powershell. The file sizes rage from 5KB-15KB.
The file data is formatted for example below:
18600 - ABCD 2204 2020-04-11 00:00:00
18600 - ABCD 2204 2020-04-11 00:00:00
18600 - ABCD 2204 2020-04-11 00:00:00
18113 - ABCD 2204 2020-04-11 00:00:00
18113 - ABCD 2204 2020-04-11 00:00:00
19873 - ABCD 2204 2020-04-11 00:00:00
18764 - ABCD 2204 2020-04-11 00:00:00
19000 - ABCD 2204 2020-04-11 00:00:00
I need to split all rows that begin with 18600, 18113, 19000, etc. (or any set of specified 5 digits) into one file and all remaining lines of data that do not begin with those numbers (else) into a second file.
So the logic is, For each line in the file if it begins with these sets of specified numbers, write to "file1" else write it to "file2".
$file = (Get-Content myfile.txt)
ForEach ($line in $file) {
If ($line -match a set of strings)
{
$newfile = all lines with set of beginning strings
}
Else {
$line | Out-File -Append different file
}
}
I'm open to any other other suggestions outside of powershell also. Thank you so much for your help.
18in sent to one file and anything else sent to another?1..88, 333..400would be a valid range.