我有一个日志file.log:grep的同时读取线替代
toto string1 tata string2 tito string3
tata tati string3
titi string1 tato string2 tati toto
.....
tutu string1 tita string2 tita string3
我需要从文件中的每一行提取字符串1,字符串和STRING3。 这些行可能包含一个或两个或三个字符串。
我第一次尝试使用,而读线做的grep:
while read line; do
z_string1=`echo $line | egrep 'string1' | cut -f2 xxx | cut -f1 xxxx`
z_string2=`echo $line | egrep 'string2' | cut -f2 xxx | cut -f1 xxxx`
z_string3=`echo $line | egrep 'string3' | cut -f2 xxx | cut -f1 xxxx`
echo "$z_string1,$z_string2,$z_string3" >> results.csv
done < file.log
可正常工作,但它不是在所有的优化,这是非常缓慢的。
谢谢你的帮助!
你想只提取stringX或包含stringX的整行吗? – 2013-04-26 04:23:47
我想提取只是stringX – 2013-04-26 04:32:19