String replace file content with patterns
With PowerShell, I want to read a text file like
number,
number(2),
number(3),
number(12,4),
number(17,4),
Find all matches to number(n,n)
in the file and replace it to decimal(n,n)
. What is the easiest way to do this with PowerShell?
一个班轮:
(gc .input.txt) -replace "number((d+,d+))", 'decimal$1' | Out-File output.txt
如果您只想在有十进制值(xx,yy)的地方更改字数,您可以这样做:
Get-Content "old file.txt" | ForEach-Object {
$_ -replace 'number((d+,d+))','decimal$1'
} | Out-File "new file.txt"
你只是想要替换的单词number
与decimal
?
Get-Content "old file.txt" | ForEach-Object {
$_ -replace "number","decimal"
} | Out-File "new file.txt"
链接地址: http://www.djcxy.com/p/29116.html
上一篇: 在bash脚本中创建时间戳变量
下一篇: 字符串用模式替换文件内容