recordsplit.ps1

2012-May-20, Sunday 11:23 am
mellowtigger: (penguin coder)
[personal profile] mellowtigger
Someone on Google Plus asked for a quick program. I couldn't format the text properly on G+, so I'm posting it here instead.

# Save this text using Notepad to a file named recordsplit.ps1
# Right-click the new recordsplit.ps1 file, then select "Run with PowerShell"
# If it doesn't run, you need to enable powershell scripts...
#      http://technet.microsoft.com/en-us/library/ee176949.aspx#EEAA

# This script separates a text file into other text files, based on the delimiter text.
# Change the first 3 variables as needed.
# If more than 999 records will be used, be sure to change the "D3" in the $newfile to an appropriate digit length ("D4")

$file='P:\ps\CraigFroehle.txt'
$delimiter='{{NEW_RECORD}}*'
$keepdelimiter=$true

$counter = 0
$fileitem = gci $file
foreach ($line in (get-content $file)) {
    if ($line -like $delimiter) {
        $counter += 1
        $newfile = $fileitem.directoryname + '\' + $fileitem.basename + '.' + ("{0:D3}" -f $counter) + $fileitem.extension
        set-content -path $newfile -value $null
    }
    if (($line -ne $null) -and ($line -ne '')) {
        if (($keepdelimiter -eq $true) -or ($line -ne $delimiter)) {
            add-content -path $newfile -value $line
        }
    }
}

Enjoy.  :)
(will be screened)
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Profile

mellowtigger: (Default)
mellowtigger

About

June 2025

S M T W T F S
1 2 34567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Powered by Dreamwidth Studios
Page generated 2025-Jun-05, Thursday 02:42 am