0

I have a text file with a single line:

Our States M0->M1: 369 M0<-M1: 974 M1->M2: 165 M0<-M2: 164

I am trying to set a variable equal to what M0->M1 is. In this case it would be 369.

Currently what I have so far:

file="stats.txt"

while read line
do
    initial_m2=`grep "M0->M3 [0-9]+" $file`
    echo "$line"
done <"$file"

This prints:

(nothing - blank line)
Our States M0->M1: 369 M0<-M1: 974 M1->M2: 165 M0<-M2: 164

Any help would be greatly appreciated.

1 Answer 1

1

If you're just tyring to read the 4th column:

while read one two three initial_m2 blah; do
  echo $initial_m2
done < $file
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was able to figure it out after this response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.