Если вы хотите анализировать несколько журналов одновременно, вы можете использовать следующий синтаксис:
tail -f /var/log/{log1,log2}
Это приведет к желаемому выводу всех необходимых журналов, поэтому вы можете использовать аргумент -e
в grep
для создания нескольких шаблонов. Так что все вместе:
tail -f /var/log/{log1,log2} | grep -ie "pattern1" -ie "pattern2" -ie "pattern3"
Что касается окрашивания grep, взгляните на этот отличный ответ.
Просто попытался настроить ваш существующий код, а не пробовать новый... Попробуйте это,
#!/bin/bash
count=0
IR=`grep -n "<name>Total Invoices Released</name>" BalanceForm.xml | cut -d: -f 1`
VIR=`grep -n "<name>Total Deep Invoice Released</name>" BalanceForm.xml | cut -d: -f 1`
while IFS= read -r line; do
NAME="`echo "$line" | awk '{$1=""; print}'`"
TOTAL=`expr $IR + 4 + $count`
TOT=`expr $VIR + 4 + $count + $count`
sed -i "{
${TOTAL}i\<operand>-Total Licensed Original $NAME</operand>
${TOTAL}i\<operand>-Total Licensed Reversal $NAME</operand>
${TOT}i\<operand>-Total Deep Licensed Original $NAME</operand>
${TOT}i\<operand>-Total Deep Licensed Reversal $NAME</operand>
}" BalanceForm.xml
count=$(expr $count + 2)
done < file.txt
Выход:
<Formula>
<name>Total Invoices Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>-Total Licensed Original This is He</operand>
<operand>-Total Licensed Reversal This is He</operand>
<operand>-Total Licensed Original This is She</operand>
<operand>-Total Licensed Reversal This is She</operand>
<operand>Total Hui Invoice Released</operand>
<operand>Total hdrt Invoices Released</operand>
<operand>Total hgfyu Invoices Released</operand>
<name>Total Deep Invoice Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>-Total Deep Licensed Original This is He</operand>
<operand>-Total Deep Licensed Reversal This is He</operand>
<operand>-Total Deep Licensed Original This is She</operand>
<operand>-Total Deep Licensed Reversal This is She</operand>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>