Hello,
I have a script that outputs lines like this one:
Code:
-VOIP- 11/20/2011 02:04:09 AM EET ONTL01 OPMD 028* BLCSIC <> mgw * DG100 (DG075) OUT ONL 000076
Now, I am trying to write another one that gets those lines from a pipe and keep the date, time, the number after the word "OPMD" (OPM, 028), the words OUT & ONL (CURRENT & PREVIOUS) and the last number (INSTANCE, 000076).
This is what I do:
Code:
#!/bin/bash
# translate_issw_alarms.sh
while read DATA; do
DATE=`echo $DATA | grep "mgw " | awk '{print $2}'`
echo "Date: "$DATE
TIME=`echo $DATA | grep "mgw " | awk '{print $3" "$4}'`
echo "Time: "$TIME
OPM=`echo $DATA | grep "mgw " | awk '{print $8}' | awk -F "*" '{print $1}'`
echo "OPM: "$OPM
CURRENT=`echo $DATA | grep "mgw " | awk '{print $15}'`
echo "Current: "$CURRENT
PREVIOUS=`echo $DATA | grep "mgw " | awk '{print $16}'`
echo "Previous: "$PREVIOUS
INSTANCE=`echo $DATA | grep "mgw " | awk '{print $17}'`
echo "Instance: "$INSTANCE
echo
done
and for example for those 3 lines:
Code:
VOIP- 11/20/2011 12:05:03 AM EET ONTL01 OPMD 003* BLCSIC <> mgw * DG100 (DG000) OUT ONL 000279
-VOIP- 11/20/2011 12:05:13 AM EET ONTL01 OPMD 003* BLCSIC <> mgw * DG000 (DG100) ONL OUT 000279
VOIP- 11/20/2011 12:07:10 AM EET ONTL01 OPMD 018* BLCSIC <> mgw * DG075 (DG000) ONL ONL 000383
I get this output:
Quote:
Date: 11/20/2011
Time: 12:05:03 AM
OPM: 003
Current: test_echo.sh
Previous: translate_issw_alarms.sh
Instance: DG100
Date: 11/20/2011
Time: 12:05:13 AM
OPM: 003
Current: test_echo.sh
Previous: translate_issw_alarms.sh
Instance: DG000
Date: 11/20/2011
Time: 12:07:10 AM
OPM: 018
Current: test_echo.sh
Previous: translate_issw_alarms.sh
Instance: DG075
The "*" mess up my output somehow but I cannot understand why!....
This is what I have in my directory:
Code:
-rwxr-xr-x 1 portal portal 192 2011-11-21 09:44 issw_alarms_translated.sh
-rwxr-xr-x 1 portal portal 242 2011-11-18 15:03 issw_logging_translated.sh
-rw-r--r-- 1 portal portal 505594 2011-11-21 10:00 logs
-rwxr-xr-x 1 portal portal 562 2011-11-18 15:00 test_echo.sh
-rwxr-xr-x 1 portal portal 623 2011-11-21 11:15 translate_issw_alarms.sh
I have tried to replace "*" with nothing ("") using sed but the second "*" (eg. mgw
* DG075) does go away and I have no idea why....
Could you help me please??