OK,
given the following input:
zsh-4.3.10[t]% cat infile
c1 5 120 + 5,10,15,10,20 0,25,40,75,95
c1 5 120 - 5,10,15,10,20 0,25,40,75,95
This code:
awk '{
fifth = split($5, _fifth, ","); sixth = split($6, _sixth, ",")
counter = 0; key = $1; flag = $4; sub(/[^ \t*]*/, "")
dummy = sprintf("%*s", length(key),x)
for (i=1; i<=sixth; i++) {
second_third = _fifth[1] + _sixth FS _fifth + _fifth[1] + _sixth
third_second = _fifth + _fifth[1] + _sixth FS _fifth[1] + _sixth
if (flag == "+")
rec = rec ? rec RS dummy OFS second_third : key OFS second_third OFS $0
else
rec_rev = rec_rev ? \
(++counter == sixth - 1 ? key OFS third_second OFS $0 : dummy OFS third_second ) RS rec_rev : \
dummy OFS third_second
}
print (flag == "+" ? rec : rec_rev)
}' OFS='\t' ORS='\n\n' infile
... produces the following output:
zsh-4.3.10[t]% nawk '{
fifth = split($5, _fifth, ","); sixth = split($6, _sixth, ",")
counter = 0; key = $1; flag = $4; sub(/[^ \t*]*/, "")
dummy = sprintf("%*s", length(key),x)
for (i=1; i<=sixth; i++) {
second_third = _fifth[1] + _sixth FS _fifth + _fifth[1] + _sixth
third_second = _fifth + _fifth[1] + _sixth FS _fifth[1] + _sixth
if (flag == "+")
rec = rec ? rec RS dummy OFS second_third : key OFS second_third OFS $0
else
rec_rev = rec_rev ? \
(++counter == sixth - 1 ? key OFS third_second OFS $0 : dummy OFS third_second ) RS rec_rev : \
dummy OFS third_second
}
print (flag == "+" ? rec : rec_rev)
}' OFS='\t' ORS='\n\n' infile
c1 5 10 5 120 + 5,10,15,10,20 0,25,40,75,95
30 40
45 60
80 90
100 120
c1 120 100 5 120 - 5,10,15,10,20 0,25,40,75,95
90 80
60 45
40 30
10 5
Merging the two scripts is left as an exercise