blob: 1be3e804775d72a00315452278c22c2e10867401 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/bin/bash
equiv_file="eepg.equiv"
usage() {
echo
[[ "$@" ]] && echo -e "ABORTED! $@\n"
echo -e "usage: ${0##*/} [channels.conf] [listsources|source to map epg from] <matchname>"
echo -e " * the 3rd argument is optional. if its \"matchname\", channel name matching is required for a positive match.\n"
exit
}
getsources() { awk -F: '{print $4}' "$1" |sort -V |uniq; }
listsources() { getsources "$1"; exit; }
(($# < 2)) && usage
[[ -e "$1" ]] || usage "$1 not found"
[[ "$2" == "listsources" ]] && listsources "$1"
[[ $(getsources "$1" |grep "$2$") ]] || usage "$2 is not a source in $1"
[[ "$3" == "matchname" ]] && match_name=1 || match_name=0
[[ -e "$equiv_file" ]] && rm "$equiv_file"
echo
tput sc
OLDIFS=$IFS; IFS=$'\n'
for i in $(awk -F: -v var="$2" '$4==var' "$1"); do
matched=0
mapto_name=" ${i%%:*}"
mapto_sid=$(awk -F: '{print $10}' <<<"$i")
mapto_line=$(awk -F: '{print $4"-"$11"-"$12"-"$10"-"$13}' <<<"$i")
mapto_source=$(awk -F: '{print $4}' <<<"$i")
for j in $(awk -F: -v var1="$2" -v var2="$mapto_sid" '$4!=var1 && $10==var2' "$1"); do
mapfrom_source=$(awk -F: '{print $4}' <<<"$j")
mapfrom_line=$(awk -F: '{print $4"-"$11"-"$12"-"$10"-"$13}' <<<"$j")
matched=1
(($match_name)) && {
[[ " ${j%%:*}" == "$mapto_name" ]] || matched=0
} || unset mapto_name
done
(($matched)) && {
((matchcount++))
outline="$mapfrom_line $mapto_line$mapto_name"
echo "$outline" >>"$equiv_file"
} || {
((unmatchcount++))
array+=( "$i" )
unset outline
}
tput rc
tput el
echo "$outline"
echo -n "matched: $matchcount - unmatched: $unmatchcount"
done
IFS=$OLDIFS
echo -e "\n"
((${#array[@]} > 0)) && for i in "${array[@]}"; do echo "NO MATCH: $i"; done
echo "wrote $equiv_file ($matchcount entries)."
|