Powershell,从txt文件中读取并格式化数据(删除行,删除它们之间的空格) [英] Powershell ,Read from a txt file and Format Data( remove lines, remove blank spaces in between)
本文介绍了Powershell,从txt文件中读取并格式化数据(删除行,删除它们之间的空格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 powershell 真的很陌生.我想用powershell读取一个txt文件,改成另一种格式.
I am really very new to powershell. I want to use powershell to read a txt file and change it to another format.
- 从 txt 文件中读取.
- 格式化数据(删除行,删除中间的空格)
- 记录数(T 000000002"9 个字符)
然后将输出写入新文件.
and then write the output to a new file.
两天前我刚刚启动了 powershell,所以我还不知道如何做到这一点.
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
这篇关于Powershell,从txt文件中读取并格式化数据(删除行,删除它们之间的空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文