iT邦幫忙

0

【請問這串文字如何歸類_2 ???】

  • 分享至 

  • xImage

我有一個文字檔
內容是

link-group SHYH_11_LAG1 access economical
dot1q pvc 1063 profile to-dot1p
l2vpn local
description 12063613-292YV000043
dot1q pvc 1096 profile to-dot1p
l2vpn local
link-group SHKK_11_LAG1 access economical
dot1q pvc 1312 profile to-dot1p
l2vpn local
description 12338398-292YV000070
dot1q pvc 1347 profile to-dot1p
l2vpn local
link-group SHYH_11_LAG1
port ethernet 5/1
port ethernet 5/2
port ethernet 5/3
dot1q pvc 241 profile from/to-dot1p
l2vpn local
description 2100000530-295YD000077

我想要變成

SHYH_11_LAG1 1063
SHYH_11_LAG1 1096
SHKK_11_LAG1 1312
SHKK_11_LAG1 1347
5/3 241

就是 link-group 後面那串字(SHYH_11_LAG1)
或是
port ethernet 後面那串字(5/3)
都有可能下面有 vlan(dot1q pvc)

不知道怎麼寫比較好

圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

6
wiseguy
iT邦超人 1 級 ‧ 2012-07-07 10:52:59
最佳解答

用 PHP 寫:

<pre class="c" name="code">foreach (file('文字檔檔名') as $line)
{
	if (preg_match('/^(link-group|port ethernet) (\S+)/', $line, $matches))
		$group = $matches[2];
	elseif (preg_match('/^dot1q pvc (\d+)/', $line, $matches))
		echo $group,' ',$matches[1],"\n";
}

我要發表回答

立即登入回答