我有一个文本文件,每行80个字符后将其余字符推送到下一行。所以我想看看如何创建一个逻辑,只有当第一行有80个字符时,我才能从下一行捕获下一个48个字符。Powershell:从下一行抓取字符,直到特定数量的字符
例子(注:堆栈只允许每行76个字符,但同样的想法)
示例文件:
This is a test where I would like this entire line and everything that will
be g
oing to this line up until character 48. 08/31/2017
所以基本上我的变量将举行以下:
This is a test where I would like this entire line and everything that will
be going to this line up until character 48.
这是我现在的代码启动逻辑:
$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"}
}
感谢
在你的循环,你应该可以算每个字符并将其推入任何变量需要。你的代码现在只会告诉你一行是否有80个字符。 –