I have a data file of the basic form:
aaa1
-> b
-> c
bbb2
-> b
ccc3
-> d
and what I want as a result is something like
b,aaa1,bbb2
c,aaa1
d,ccc3
So I am trying this code:
typeset -A CI
if [ "$#" -eq 0 ] ; then
echo "USAGE: $0 input_file" >&2
exit 1
fi
prefix="--*> "
exec < "$1"
read line
bussvc=$line
line2=""
while read line2 ; do
case "$line2" in
-* )
plain="${line2#$prefix}"
echo $plain,$bussvc
if [ "CI[$plain]" ] ; then
CI[$plain]="${CI[$plain]},$bussvc"
else
CI[$plain]=$bussvc
fi
;;
* )
bussvc=$line2
line2=""
;;
esac
done
for index in "${!CI[@]}" ; do
print "CI[$index],${CI[$index]}"
done
The first issue I am having is setting $plain. The idea is that I want to skip the first portion of the string when it starts with a -. It could be -> or --> or --->, etc. followed by a space.
It looks to me like bash does not want a regular expression in the pattern to be matched.
Since the most frequent case is "-> ", to try and make progress, I replace the pattern with the static "-> ".
The next issue is this:
(Line 25) read line2
(Line 26) case "$line2" in
(Line 28) plain=ABC-ROVER-HEAD-XYZ
(Line 30) echo ABC-ROVER-HEAD-XYZ,AP_ABC Networking
ABC-ROVER-HEAD-XYZ,AP_ABC Networking
(Line 31) '[' 'CI[ABC-ROVER-HEAD-XYZ]' ']'
./genbussvc.ksh: line 32: CI: bad array subscript
(Line 32) CI[$plain]=',AP_ABC Networking'
./genbussvc.ksh: line 32: CI[$plain]: bad array subscript
Why is the string called a bad array subscript?
Thank you for your help.
aaa1
-> b
-> c
bbb2
-> b
ccc3
-> d
and what I want as a result is something like
b,aaa1,bbb2
c,aaa1
d,ccc3
So I am trying this code:
typeset -A CI
if [ "$#" -eq 0 ] ; then
echo "USAGE: $0 input_file" >&2
exit 1
fi
prefix="--*> "
exec < "$1"
read line
bussvc=$line
line2=""
while read line2 ; do
case "$line2" in
-* )
plain="${line2#$prefix}"
echo $plain,$bussvc
if [ "CI[$plain]" ] ; then
CI[$plain]="${CI[$plain]},$bussvc"
else
CI[$plain]=$bussvc
fi
;;
* )
bussvc=$line2
line2=""
;;
esac
done
for index in "${!CI[@]}" ; do
print "CI[$index],${CI[$index]}"
done
The first issue I am having is setting $plain. The idea is that I want to skip the first portion of the string when it starts with a -. It could be -> or --> or --->, etc. followed by a space.
It looks to me like bash does not want a regular expression in the pattern to be matched.
Since the most frequent case is "-> ", to try and make progress, I replace the pattern with the static "-> ".
The next issue is this:
(Line 25) read line2
(Line 26) case "$line2" in
(Line 28) plain=ABC-ROVER-HEAD-XYZ
(Line 30) echo ABC-ROVER-HEAD-XYZ,AP_ABC Networking
ABC-ROVER-HEAD-XYZ,AP_ABC Networking
(Line 31) '[' 'CI[ABC-ROVER-HEAD-XYZ]' ']'
./genbussvc.ksh: line 32: CI: bad array subscript
(Line 32) CI[$plain]=',AP_ABC Networking'
./genbussvc.ksh: line 32: CI[$plain]: bad array subscript
Why is the string called a bad array subscript?
Thank you for your help.