I have refer this Grep the lines between the occurrence of the same pattern , I don't want to split into file; instead, I want to store it into an array. File
0 1 2 3 0 1 2 0 1
My script code is:
total=$(sed -n \$= count.txt) c=0 k=0 lineno=0 var="0" for i in $(cat count.txt); do if ["$i" -eq "$var"] then arr[$((k++))]=c c=0 c=$((c+1)) else c=$((c+1)) if ["$lineno" -eq "$total"] then arr[$((k++))]=c fi fi lineno=$((lineno+1)) done
The above logic is tested on C++ launguage which on printing the array shows :
0 4 3 2
Firstly, my script is showing error like
line 9: [0: command not found.
Secondly, is there any efficient method to store the repeated count in array, like above output?