Question:
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.
Answer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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 |