Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell - Get first x characters from each line of text

$
0
0

I've got a text document and want to preform two things: 1) delete first 5 lines and 2) for each line of text, grab only the first 8 characters.  To help me in my logic, I've got this broken down into steps, with each step creating a new file.  My problem is with the last step of the script, $file3 is never created and I'm clueless.

cls
$file1 = 'C:\cs1.txt'
$file2 = 'C:\cs2.txt'
$file3 = 'C:\cs3.txt'
$lines = @()

(Get-Content $file1 | Select-Object -Skip 5) | Set-Content $file2

Get-Content $file2 | ForEach-Object {$line=$_[5..8]} | Add-Content $file3


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>