is probably a stupid question, but can't see the reason for while abort.
i have a file like this:
"id": "00000000000000000",
"visibilitystate": 1,
"profilestate": 8
"somethingelse": "abc",
"id": "99999999999999999",
"againsomethingelse": "cba"
"visibilitystate": 0,
"profilestate": 9
one million or more repetitions, number,designation and value can be different between id and id, but id is always different. my first thought was read in a loop, store the value in a array and later insert into mysql-db.
i try this:
set -x
#Data extract array
array=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#Control array
array2=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
while read a; do
if [[ ${array2[0]} == 1 ]]; then
awk '/"id":/ { exit 42 }'
if [[ $? -eq 42 ]]; then
echo mysql
array2[0]=0
fi
fi
if [[ ${array2[0]} == 0 ]]; then
awk '/"id":/ { exit 42 }'
if [ $? -eq 42 ]; then
array[0]=`sed -n 's/.*"id":."\(.*\)",.*/\1/p'`
array2[0]=1
fi
fi
done <testf
set +x
after read one line, the loop exit, don't understand why.
output:
+ array=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
+ array2=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
+ read a
+ [[ 0 == 1 ]]
+ [[ 0 == 0 ]]
+ awk '/"id":/ { exit 42 }'
+ '[' 42 -eq 42 ']'
++ sed -n 's/.*"id":."\(.*\)",.*/\1/p'
+ array[0]=
+ array2[0]=1
+ read a
+ set +x
can someone help me?