5.08*3.91*0.2
1.90*4.91*0.2
0.63*1.90*0.1
1.49*5.54*0.2
2.30*4.23*0.3
5.18*3.69*0.2
6.23*4.38*0.2
3.61*4.28*0.2
4.57*2.40*0.2
6.70*2.40*0.2
7.28*2.45*0.2
1.90*3.40*0.2
现在有上面这样的一个文本内容,
现在我要做三件事:
1, 把每一行算式的值计算出来
2, 求每一行值的总值---------统计
3, 把结果写会原来的文件
脚本如下:
$text = Get-Content -Path e:\temp.txt
$count = 0;
Set-Content -Path e:\temp.txt -Value "";
foreach($t in $text){
$count = $count + (Invoke-Expression $t)
($t+" = "+ (Invoke-Expression $t)) | Out-File -Append -Encoding utf8 -FilePath e:\temp.txt
}
("合计:" + $count) | Out-File -Append -Encoding utf8 -FilePath e:\temp.txt
再次打开temp.txt文件文件,内容如下:
5.75 * 0.55 * 0.2 = 0.6325
4.78 * 0.55 * 0.2 = 0.5258
7.19 * 0.55 * 0.2 = 0.7909
6.33 * 0.55 * 0.2 = 0.6963
3.73 * 4.39 * 0.2 = 3.27494
6.44 * 4.39 * 0.2 = 5.65432
5.11 * 4.39 * 0.2 = 4.48658
6.22 * 4.39 * 0.2 = 5.46116
2.21 * 4.39 * 0.2 = 1.94038
0.85 * 4.10 * 0.2 = 0.697
4.09 * 4.39 * 0.2 = 3.59102
4.71 * 0.80 * 0.2 = 0.7536
3.73 * 4.86 * 0.2 = 3.62556
1.15 * 4.80 * 0.2 = 1.104
1.29 * 5.58 * 0.2 = 1.43964
2.41 * 0.58 * 0.2 = 0.27956
6.52 * 4.42 * 0.2 = 5.76368
6.70 * 4.42 * 0.2 = 5.9228
5.19 * 3.39 * 0.2 = 3.51882
2.44 * 5.58 * 0.2 = 2.72304
合计:52.8816