Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Check last line `r`n

$
0
0

Hi,

I am trying to split the source file based on specific size.

<code>

param(
[string]$fromFolder,
[string]$rootName,
[string]$ext,
[int]$fl_size
)

$NumOfParams=4
If (($PSBoundParameters.values | Measure-Object | Select-Object -ExpandProperty Count) -lt $NumOfParams)
{"`nPlease provide all the parameters"
"Usage : .\split_src_file.ps1 <fromFolder> <file_name> <file_ext> <file_size_to_split>`n"
EXIT}
 
$from = "{0}{1}.{2}" -f ($fromFolder, $rootName, $ext)
$fromFile = [io.file]::OpenRead($from)
$buff = new-object byte[] $fl_size
 
$count = $idx = 0
 
try {
    "`nSplitting $from using $fl_size bytes per file.`n"
    do {
        $count = $fromFile.Read($buff, 0, $buff.Length)
        if ($count -gt 0) {
            $to = "{0}{1}_{2}.{3}" -f ($fromFolder, $rootName, $idx, $ext)
            $toFile = [io.file]::OpenWrite($to)
            try {
                $tofile.Write($buff, 0, $count)
    $tofile.Close()
    $chk=Get-Content $to | select -Last 1
    Write-Host $chk
    $chk -match '[`n]'
            } finally {
                $tofile.Close()
            }
        }
        $idx ++
    } while ($count -gt 0)
}
finally {
    $fromFile.Close()
}

</code>

I got the above code to split the file. But it is splitting the row at the end of the file, if file exceeds that specific size.

Actual Record : Nice,,KEN,,6940,Y,20001,001100,STATE,IND,4,Pub,20100823,20101217,F,,,,,,N,,,,,,,,,,,[CR][LF]

For example, My first split file contains (Nice,,KEN,,6940,Y,20001,00110) at the end of the file and my second file contains the remaining of that record (0,STATE,IND,4,Pub,20100823,20101217,F,,,,,,N,,,,,,,,,,,[CR][LF])

Now, I want to check my first split file for [CR][LF] or `r`n at the end of the file, if it doesn't contain then include that in the second file. Please let me know how to achieve this.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles