I am really very new to powershell. I want to use powershell to read a txt file and change it to another format.
- Read from a txt file.
- Format Data( remove lines, remove blank spaces in between)
- Count of records ( "T 000000002" 9 chars)
and then write the output to a new file.
I just started powershell two days ago so I don't know how to do this yet.
function Count-Object() {
begin {
$count = 0
}
process {
$count += 1
}
end {
$count
}
}
$a= get-content .\members.txt |
Foreach-Object { ($_ -replace '\s','') } |
Foreach-Object { ($_ -replace '-','') } |
Foreach-Object { ($_ -replace 'OP_ID','') } |
Foreach-Object { ($_ -replace 'EFF_DT','') } |
Where-Object { $_ -ne '' }|
set-content .\newmembers.txt
$b = Get-Content .\newmembers.txt |
Count-Object $b
"T {0:D9}" -f $b | add-content .\newmembers.txt
I also like the ? used in place of the where-object to trim it down just that much more.
Get-Content file.txt | ?{ $_ } > file2.txt