【发布时间】:2015-05-19 01:53:30
【问题描述】:
我在让 windows powershell 做我想做的事情时遇到了一些问题。基本上,我的当前文件夹中有 24 个子文件夹,分别命名为 Angle1、Angle2 等,直到 Angle 24。
在每个子文件夹中都有一个名为 output.txt 的文件。在 output.txt 中,有 10 列数据,以空格分隔。我想在每个子文件夹中获取每个 output.txt 文件的第 9 列,并将它们全部放在父文件夹中名为 total.txt 的新文件中。所以,最终,我将有 24 列数据,每列用空格分隔。 total.txt 的第一列对应 Angle1 中 output.txt 的第 9 列,以此类推
请注意,Angle 文件夹还有其他我想忽略的子文件夹。
尽管尝试了很多次,但我还是无法让它发挥作用。我不确定是否需要使用 -Recurse 选项来执行此操作,或者 Powershell 是否甚至能够执行此操作。这里有没有人是powershell专家,可以说这是否可能?
一个小的除了来自一个 output.txt 文件:
1348 2 26.0785 3.18115 20.5328 -0.79613 3.18115 2.51545 4.13292 0.278888
1348 2 26.8091 2.07125 19.4069 -0.0655152 2.07125 1.38956 2.49505 0.254024
1348 2 24.162 3.90054 20.4261 -2.71258 3.90054 2.40877 5.32677 0.0208912
1348 2 24.1527 3.90493 20.4233 -2.72189 3.90493 2.40595 5.33346 0.00646916
1348 2 24.1436 3.88005 20.4429 -2.73095 3.88005 2.42555 5.32881 0.0127918
1348 2 24.1087 3.87723 20.4519 -2.76586 3.87723 2.43455 5.34882 0.0198102
1348 2 24.2572 3.83432 20.4136 -2.61737 3.83432 2.39624 5.22442 0.0243901
1348 2 24.1609 3.7174 19.8739 -2.71375 3.7174 1.85659 4.9629 0.0838124
我使用的代码是在 Linux 中,在某种程度上可以工作:
awk '{print $9}' Angle1/output.txt >>tmp
for ((i=2;i<25;i++))
do
awk '{print $9}' Angle${i}/output.txt |paste -d " " tmp - >>total.txt
mv total.txt tmp
done
mv tmp total.txt
但是,现在我需要在 Powershell 中运行,而不是在 linux 中运行。目前我真的没有任何远程工作的代码。基本上是 Get-Child 命令等的集合,但没有什么能接近我想要的。
【问题讨论】:
-
你能发布一个 output.txt 的例子和你到目前为止尝试过的代码吗?这当然可以使用 powershell。
标签: powershell