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.
done < ms.txt
and that works, but I don't know how to modifyms.txt
and the modified input pass to while cycle. – Cygne Apr 24 '21 at 11:46set -x
before code blocks that behave unexpectedly, andset +x
after them. That will print the commands including values of variables before they are executed. – berndbausch Apr 24 '21 at 12:02done < ms.txt
fordone < <(echo "$input")
(it was written there) and it works. :) :D – Cygne Apr 24 '21 at 12:33