Good afternoon,
I wanted to replace the word “FE” 'for “01” in several csv files that are on board. I have this what I’m doing wrong ??
$files = Get-ChildItem C:\Users\ricardo.braganca\Desktop\NEW\ -Filter *.txt -Recurse
$CSVFolder = ‘C:\Users\ricardo.braganca\Desktop\NEW*.csv’
$OutputFile = ‘C:\Users\ricardo.braganca\Desktop\NEW\dados1.txt’
$OutputFile2 = ‘C:\Users\ricardo.braganca\Desktop\NEW\dados2.txt’
Group objects by number
foreach ($file in $files){
$groups = Get-Content $file.FullName | ConvertFrom-Csv -Delimiter ‘|’ -Header H1,H2,H3,H4,H5,H6,H7,H8,H9,H10,H11,H12,H13,H14,H15,H16,H17,H18,H19,H20,H21,H22,H23,H24,H25,H26,H27,H28,H29,H30,H31,H32,H33,H34,H35,H36,H37,H38,H39,H40,H41,H42,H43,H44,H45,H46,H47,H48,H49,H50,H51,H52,H53,H54,H55,H56,H57,H58,H59,H60,H61,H62,H63,H64,H65,H66,H67,H68,H69,H70,H71,H72,H73,H74,H75,H76,H77,H78,H79,H80 |
Group-Object -Property H9
$groups | ForEach-Object {If ($.group.H1 -like ‘FE’ -AND $.group.H14 -like ‘MAI000’ -AND $.group.H1 -like ‘01’ -and $.group.H14 -like ‘MAIFIM’){
$.group | Export-Csv "C:\Users\ricardo.braganca\Desktop\NEW$($.Name).csv" -NoTypeInformation -Encoding Unicode }}
}
#join files in txt
$CSV= @();
Get-ChildItem C:\Users\ricardo.braganca\Desktop\NEW$($.Name).csv | ForEach-Object { {$ -replace ‘“FE”’ ,‘“01”’ }
$CSV += @(Import-Csv -Path $_)
}
$CSV | Export-Csv -Path $OutputFile -NoTypeInformation -Force -Encoding Unicode
#Remove csv files
Remove-Item -Path $CSVFolder -Filter *.csv -Force -Recurse