Counting the number of lines between same repeating pattern
Clash Royale CLAN TAG #URR8PPP 0 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 count.txt contain: 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? bash awk sed share | improve this question edited 2 days ago Rui F Ribeiro 39.3k 14 79 131 asked Dec 27 '18 at 13:01 Arya Arya 1 ...