2014-05-02 55 views

回答

2
list_of_strings=(a b "hello world") 
grep -oF -f <(printf "%s\n" "${list_of_strings[@]}") file.txt 

使用一個process substitution處理字符串的印刷陣列就像一個文件,然後使用一些grep的選項(檢查你的男人頁)提取所需的字符串

而且,使用正則表達式交替像你似乎想:​​

grep -oE "$(IFS='|'; echo "${list_of_strings[*]}")" file 
+0

謝謝!這有幫助! – Karthik

相關問題