【发布时间】:2016-03-19 14:42:43
【问题描述】:
我有以下输出(在 linux 中):
wwn = 5001248018b6d7af
node_wwn = 5001248018b6d7ae
wwn = 5001248118b6d7af
node_wwn = 5001248118b6d7ae
我需要解析输出,使其看起来像这样:
50:01:24:80:18:b6:d7:ae:50:01:24:80:18:b6:d7:af
50:01:24:81:18:b6:d7:ae:50:01:24:81:18:b6:d7:af
输出是 node_wwn 及其 wwn。
我使用一些 C# 应用程序完成了这项工作,但它太复杂了,无法获取输出并将其传递给程序。
string command = "cat /proc/sll/info |grep -B 9 up| grep wwn";
string temp;
string []commandOutput;
string[] wwns;
string[] wwpns;
hbaList = new List<HBA>();
commandOutput = (exec.RunCommand(command)).Trim().Split('\n');
wwns = Array.FindAll(commandOutput, item => item.StartsWith("wwn = "));
wwpns = Array.FindAll(commandOutput, item => item.StartsWith("node_wwn = "));
for (int i =0; i<wwns.Length;i++)
{
hba = new HBA();
temp = string.Format("{1}", (wwpns[i].Split('='))).Trim();
temp += string.Format("{1}", (wwns[i].Split('='))).Trim();
temp = Regex.Replace(temp, ".{2}", "$0:");
temp = temp.Remove(temp.Length - 1);
hba.ID = temp;
hbaList.Add(hba);
}
请帮忙...
感谢阿尔莫格
【问题讨论】:
-
发布你的尝试..
-
发表感谢,,,我不熟悉 sed 和 awk 等 linux 解析命令...请帮助
-
你为什么使用
grep -B9?还有哪些您没有向我们展示的其他输出?整个任务可以通过单个 Awk 脚本轻松处理,但我们需要了解预期的输入。
标签: regex linux parsing awk sed