I have a text file that I am trying to modify. I am taking the input file that has lines of the form of
(y+1/4,-x+1/2,z+3/4)
and trying to chan
Here's an approach that may simplify the parsing. Read each line into an array using IFS set to all possible delimiters and characters you don't care about:
while IFS=$'\(\)+,' read -ra line; do
for i in 1 3 5; do
case "${line[$i]}" in
x) printf "%s\t%s\t%s\t" 1 0 0 ;;
y) printf "%s\t%s\t%s\t" 0 1 0 ;;
z) printf "%s\t%s\t%s\t" 0 0 1 ;;
-x) printf "%s\t%s\t%s\t" -1 0 0 ;;
-y) printf "%s\t%s\t%s\t" 0 -1 0 ;;
-z) printf "%s\t%s\t%s\t" 0 0 -1 ;;
esac
done
for i in 2 4 6; do
printf "%s\t" "${line[$i]}"
done
echo
done < "$filename"