Script Enhancement Request

Question

Hi,

I was trying to split a file into multiple files by line count and then add a line of content at the top and the bottom. I came up with this solution but I was wondering if someone has a cleaner one.

$d=0; Get-Content c:\data\file.txt -ReadCount 10 | %{$d++; $_ | Out-File file_$d.txt}

while ($d -ge 0) {
$new = 'A' 
$data = get-content c:\data\file_$d.txt
Set-content c:\data\file_$d.txt $new
add-content c:\data\file_$d.txt $data
$new = 'Z'
Add-content c:\data\file_$d.txt $new
$d--
}

Edit: Preferably a one line now that a solution has been posted.

Posted Feb 17, 2017, 2:31 AM UTC · edited

33
Loading comments…