0

我有一个 powershell 脚本,可以将InstanceParentNodeValue导出到我导出到 CSV 文件的列表中。我在多台机器上运行它并将它们附加到主列表中。例子:

Server1
Instance        ParentNode          Value
----------------------------------------
InstanceA       BatchName           BatchX
InstanceA       SourceFolderPath    \\server\feeds\BlahBlah
InstanceA       DestinationLocation \\Server\archive\BlahBlah
InstanceA       DestinationLocation \\Server\consumption\BlahBlah
InstanceA       BatchName           BatchT
InstanceA       SourceFolderPath    \\server\feeds\i.BlahBlahFailed
InstanceA       DestinationLocation \\Server\archive\i.BlahBlahFailed
InstanceA       DestinationLocation \\Server\consumption\BlahBlahFailed

ServerB
----------------------------------------
InstanceC       BatchName           BatchX
InstanceC       SourceFolderPath    \\Server\archive\i.BlahBlahFailed
InstanceC       DestinationLocation \\Server\archive2\BlahBlah
InstanceC       DestinationLocation \\Server\consumption2\BlahBlah

现在,其中一些是SourceFolderPaths其他服务器上的目的地的次数增加了 100 次以上。最终目标是能够从头到尾获得一个提要路径列表。任何语言都可以 C#、PHP 等...

4

1 回答 1

0

这是解决此问题的一种方法:

        string[] input = File.ReadAllText("textfile3.txt").Split(new string[1] { "SourceFolderPath" }, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 1; i < input.Count(); i++)
        {
            listBox1.Items.Add(input[i].Substring(0,input[i].IndexOf("Instance") - 1).Trim());
        }

如果不希望将整个文件读入内存,您可以像这样遍历文件:

        StreamReader sr = new StreamReader("textfile3.txt");
        while (!sr.EndOfStream)
        {
            string line = sr.ReadLine();
            int index = line.IndexOf("SourceFolderPath");
            if (index >= 0)
            {
                listBox1.Items.Add(line.Substring(index + 16).Trim());
            }
        }

我使用列表框项目集合来存储路径。您也可以轻松地使用 List 来存储它们。

于 2013-08-06T01:19:31.490 回答