SUN(SM) ALERT WEEKLY SUMMARY REPORT を html に変換するスクリプト

メールで受け取った、”SUN(SM) ALERT WEEKLY SUMMARY REPORT” を HTML に変更する。


sa2html.sh

#!/bin/bash
LANG=C

if [ “$1” = “” ]; then
echo “Usage: $0 [SUN(SM)_ALERT_WEEKLY_SUMMARY_REPORT_FILE]”
exit 1
fi

SUNALERT=`cat $1`

printf “$SUNALERT\n” \
| grep “Week of” \
| sed ‘s/^\(.*\)$/<b>□SUN(SM) ALERT WEEKLY SUMMARY REPORT (\1)<\/b>/’

N_SLINE=`printf “$SUNALERT\n” \
|nl -b a \
|grep “Newly Released Sun Alert Notifications” \
|grep -v “*” \
|awk ‘{printf”%d\n”,$1-1}’`
N_ELINE=`printf “$SUNALERT\n” \
|nl -b a \
|grep “Updated Sun Alert Notifications” \
|grep -v “*” \
|awk ‘{printf”%d\n”,$1-2}’`
N_DIFF=`echo “$N_SLINE $N_ELINE”|awk ‘{printf”%d\n”,$2-$1}’`

NEWALERT=`printf “$SUNALERT\n”|head -$N_ELINE|tail -$N_DIFF`

#-debug
#echo “$N_SLINE”
#echo “$N_ELINE”
#echo “$N_DIFF”
#printf “$NEWALERT\n\n”

IDLINES=`printf “$NEWALERT\n”|nl -b a|grep “Sun Alert ID”|awk ‘{printf”%d\n”,$1}’`
SYNLINES=`printf “$NEWALERT\n”|nl -b a|grep “Date Released:”|awk ‘{printf”%d\n”,$1-1}’`
VIEWLINES=`printf “$NEWALERT\n”|nl -b a|grep “To view”|awk ‘{printf”%d\n”,$1+1}’`

LINES=`printf “$IDLINES\n$SYNLINES\n$VIEWLINES”|sort -n`

#-debug
#echo “$IDLINES”
#echo “$SYNLINES”
#echo “$VIEWLINES”
#echo “$LINES”

for i in `printf “%d+%d+%d\n” $LINES`
do
IDLINE=`echo $i|awk -F+ ‘{print$1}’`
SYNLINE=`echo $i|awk -F+ ‘{printf”%d\n”,$2}’`
SYN_DIFF=`echo $i|awk -F+ ‘{printf”%d\n”,$2-$1}’`
VIEWLINE=`echo $i|awk -F+ ‘{print$3}’`

ID=`printf “$NEWALERT\n”|head -$IDLINE|tail -1|awk ‘{print $4}’`
SYN=`echo $(printf “$NEWALERT\n”|head -$SYNLINE|tail -$SYN_DIFF|sed ‘s/^Synopsis: //’)`
VIEW=`printf “$NEWALERT\n”|head -$VIEWLINE|tail -1`

#-debug
#echo “$ID”
#echo “$SYN”
#echo “$VIEW”

echo “ <a href=\”$VIEW\”>$ID:$SYN</a>”
done

タイトルとURLをコピーしました