2014-04-16 45 views
-1

我需要提取一部分字符串。 字符串是如下,使用SED或GREP進行模式匹配

/ba/mn/first one /ba/mn/second /ba/mn/third

等。

有數百個這樣的字符串。我需要從字符串中提取下面的部分, 第一個 第二 第三 等

請幫我做這個,因爲我是新來的模式匹配的世界,我正在學習它。

謝謝, Sunil。

我使用的代碼是, grep s/^.*branches/

回答

0

隨着bash單行:

while read line; do basename "$line"; done<yourfile 

sed隨着:

sed -n 's#^\(.*\)/\([^/]*\)$#\2#p' yourfile 
0

使用basenamexargsxargs -a yourfile -n1 basename