ログファイルがあります.log:
toto string1 tata string2 tito string3
tata tati string3
titi string1 tato string2 tati toto
.....
tutu string1 tita string2 tita string3
ファイルのすべての行から string1、string2、および string3 を抽出する必要があります。行には、1 つ、2 つ、または 3 つの文字列を含めることができます。
私の最初の試み while read LINE do 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
これは期待どおりに機能しますが、まったく最適化されておらず、非常に遅いです。
ご協力ありがとうございました!