PowerShell Import-CSV, For Each Item, Delete String After Symbol -
if have list this:
user1.xxxx user2.xxxxx user3.xxx
how can create each loop , delete after period? how delete before well? have basics written, , tried few misguided attempts manipulating .substring etc...:
$allusers = import-csv -path "c:\folder1\all user.csv" $allusers | foreach { } | export-csv -path "c:\folder1\removed.csv"
the easiest way in case use split method:
$allusers = get-content somepath | foreach { $_.split('.')[0] } | set-content somepath
[0] taking first element array of elements created split, in case there 2 elements, before dot , after dot. take after dot [1] instead of [0].
also, not want use import-csv since in case easier work raw data.
edit: since i'm not sure actual csv looks might want use this:
$data = import-csv somepath $results = @() foreach ($line in $data) { $line.column_that_needs_editing = $line.column_that_needs_editing.split('.')[0] $results += $_ } $results | export-csv someotherpath
Comments
Post a Comment