0

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 &quot;$line&quot; | cut -d &quot;:&quot; -f 3 - )
  status[$k]=&quot;${status[$k]}+$c&quot;

  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.

Cygne
  • 1
  • Also state what you want. You don't ask a question. Do you want help with some modifications of input, or do you want help with something that doesn't work well anymore? Or do you want help with something else? – berndbausch Apr 24 '21 at 11:43
  • Ok thank you, I thought that it is not important. :) – Cygne Apr 24 '21 at 11:44
  • I want to help how to modify the input, in the first case I use done < ms.txt and that works, but I don't know how to modify ms.txt and the modified input pass to while cycle. – Cygne Apr 24 '21 at 11:46
  • Without knowing the input and the modifications, and without seeing the error messages, it's impossible to say anything. – berndbausch Apr 24 '21 at 11:59
  • What you can do: Add set -x before code blocks that behave unexpectedly, and set +x after them. That will print the commands including values of variables before they are executed. – berndbausch Apr 24 '21 at 12:02
  • @Freddy Yes, thank you. I don't understand it well but I changed done < ms.txt for done < <(echo "$input") (it was written there) and it works. :) :D – Cygne Apr 24 '21 at 12:33

0 Answers0