I'm trying to echo the information/variables for each line of an alarmfile (named critical), using while read line to get each line of the alarmfile (might be a lot of lines on critical file):
while read line
do
{
s=`grep -Po '(?<=(sender:)).*' critical| cut -d ',' -f1`
t=`grep -Po '(?<=(time:)).*' critical| cut -d '.' -f1`
d=`grep -Po '(?<=(.1.3.6.1.4.1.2285.1.1.8:)).*' critical| cut -d ',' -f1`
echo "Sender: $s" >>critical_body
echo "Time: $t" >>critical_body
echo "Description: $d" >>critical_body
}
done < critical
The output i need is to get it structured like below:
Sender: xyz1
Time: 2021/08/11 22:14:19
Description: Lost communication with device
Sender: xyz2
Time: 2021/08/13 15:58:02
Description: Memory usage is above normal: 10% free
But i get the following, it seems that the variables values are printed all in one iteration separated with a /n and not one by one as i want.
Sender: xyz1
xyz2
Time: 2021/08/11 22:14:19
2021/08/13 15:58:02
Description: Lost communication with device
Memory usage is above normal: 10% free
Sender: xyz1
xyz2
Time: 2021/08/11 22:14:19
2021/08/13 15:58:02
Description: Lost communication with device
Memory usage is above normal: 10% free
Can someone help me? I am trying to find what's wrong, im relatively new on bash scripting.
cat critical
2021-08-11 22:14:19,550 INFO [com.optimization.ems.snmp.FnTrapReceiver] raw trap record inserted: com.optimization.ems.ems.model.snmp.RawTrapid: null, oid: .1.3.6.1.4.1.2285.1.2.14, time: 2021/08/11 22:14:19.547, sender: xyz1, version: 2, varbind: .1.3.6.1.2.1.1.3.0:5d 11h 0m 35s 350ms,.1.3.6.1.6.3.1.1.4.1.0:.1.3.6.1.4.1.2285.1.2.14,.1.3.6.1.4.1.2285.1.1.6:xyz1,.1.3.6.1.4.1.2285.1.1.8:Lost communication with device,.1.3.6.1.4.1.2285.1.1.3:5,
2021-08-13 15:58:02,083 INFO [com.optimization.ems.snmp.FnTrapReceiver] raw trap record inserted: com.optimization.ems.ems.model.snmp.RawTrapid: null, oid: .1.3.6.1.4.1.2285.1.2.3, time: 2021/08/13 15:58:02.79, sender: xyz2, version: 2, varbind: .1.3.6.1.2.1.1.3.0:98d 21h 39m 6s 60ms,.1.3.6.1.6.3.1.1.4.1.0:.1.3.6.1.4.1.2285.1.2.3,.1.3.6.1.4.1.2285.1.1.2:15:58:02 13/08/2021,.1.3.6.1.4.1.2285.1.1.3:5,.1.3.6.1.4.1.2285.1.1.8:Memory usage is above normal: 10% free,
criticalfor every line and ignoring$linevariable