I my code I have while cycle which reads from file:
teams=()
status=()
novy=true
j=0
k=0
while read line; do
name=$( echo "$line" | cut -d ":" -f 1 - )
for i in "${teams[@]}"; do
if [ "$i" = "$name" ]; then
novy=false
c=$( echo "$line" | cut -d ":" -f 3 - )
status[$k]="${status[$k]}+$c"
break
fi
k=$(( k+1 ))
novy=true
done
if "$novy"; then
teams[$j]="$name"
status[$j]=$( echo "$line" | cut -d ":" -f 3 - )
j=$(( j + 1 ))
novy=false
fi
k=0
done < ms.txt
But now I want to modify input ms.txt so I tried this:
input=$( cat ms.txt )
some modifiations of input (by echo "$input" I verified that the input is in right form)
echo "$input" | while read line; do
name=$( echo "$line" | cut -d ":" -f 1 - )
for i in "${teams[@]}"; do
if [ "$i" = "$name" ]; then
novy=false
c=$( echo "$line" | cut -d ":" -f 3 - )
status[$k]="${status[$k]}+$c"
break
fi
k=$(( k+1 ))
novy=true
done
if "$novy"; then
teams[$j]="$name"
status[$j]=$( echo "$line" | cut -d ":" -f 3 - )
j=$(( j + 1 ))
novy=false
fi
k=0
done
But now the code doesn't work, I don't know why. The while cycle doesn't read the input same as before and it prints some errors.