I have a text file that after 80 characters per line pushes the remaining characters to the next line. So I'd like to see how I can create a logic that allows me to capture the next 48 characters from the following line only when there is 80 characters in the first line.
Example (Note: Stack only allows 76 characters per line, but same idea)
Sample File:
This is a test where I would like this entire line and everything that will
oing to this line up until character 48. 08/31/2017
So basically my variable would hold the following:
This is a test where I would like this entire line and everything that will
be going to this line up until character 48.
This is my current code that started the logic:
$lineArray = Get-Content "c:\sample.txt"
ForEach ($line in $lineArray )
If ($line.length -eq 80) {Write-Host $line.length " - Max characters
Reached"}
else {Write-Host $line.length " - Within Limits"}
Thanks
–
For anyone curious... I was able to accomplish it by using the following code:
$lineArray = Get-Content "C:\sample.txt"
$lineNumber = 0
ForEach ($line in $lineArray )
{#Write-Host $line.length
If ($line.length -eq 80)
{#Write-Host $line.length " - Max characters Reached"
$nextLine = $lineArray[$lineNumber +1]
$retrieve48 = $nextLine.substring(0,48)
$newLine = $line + $retrieve48
Write-Host = $newLine
else {Write-Host $line.length " - Within Limits"}
$lineNumber++
https://stackoverflow.com/questions/45990399/powershell-grab-characters-from-next-line-until-a-specific-number-of-characters/45990688#45990688
share
improve this answer
–
–
–