2013-10-21 49 views
1

如何提取shell腳本中的特定字符串? 我有以下類型的字符串,這是目前在兩條線: -Shell字符串提取

「我的名字叫安迪

,我很興奮的工作{」在上面的句子

,所以我需要解壓「我對工作感到興奮」。

回答

1

使用bash

$ a="My name is andy 
    and I'm excited about work {" 
$ [[ "$a" =~ .*(I\'m.*work).* ]] && echo "${BASH_REMATCH[1]}" 
I'm excited about work 

使用grep

$ grep -oP "(I'm.*work)" <<< "$a" 
I'm excited about work