0

I wanted to read a ASCII file inside a while-loop with each iteration I want to read each row starting from the SECOND row of the file. After a lot of searching what I came up with is in below:

    a=1
    while [ $a -le 04 ]
    do
    while read p q r; do
    root -l macro.C\($r\) #the operation is dependent of the entries of the third column in the ASCII file
    done < ascii.txt
    a=`expr $a + 1`
    done

But, this doesn't seem to serve my purpose. Firstly I want to skip the first row, but don't know how to do that. Also, what it does is, it feeds all the entries of that column for each iteration of the outer while-loop.

Can anybody help me with this?

Thanks and regards, Saumyen

  • Does this answer your question? [Capturing multiple line output into a Bash variable](https://stackoverflow.com/questions/613572/capturing-multiple-line-output-into-a-bash-variable) – F. Hauri - Give Up GitHub Mar 18 '21 at 18:35
  • Have a look at [this answer](https://stackoverflow.com/a/64330514/1765658) – F. Hauri - Give Up GitHub Mar 18 '21 at 18:36
  • 1
    Try `{ read foo; while ...;done ;} < ascii.txt` – F. Hauri - Give Up GitHub Mar 18 '21 at 18:37
  • What have you tried to do? Surely you can - delete first row of input `sed -e '1d' < file | while read ....` then do what you want? – Mr R Mar 18 '21 at 23:03
  • Thanks a lot @Hauri. I tried with the following as per your suggestion (`{ read foo; while ...;done ;} < ascii.txt`), but what I am getting with that is, for each iteration of the outer loop all the rows are being read from the ascii file due to the second while-loop nested inside of it. Could you suggest any fix for that? – Saumyen Kundu Mar 20 '21 at 20:38
  • In the meantime, I tried something else, which is feeding the contents of the column to an array. `#!/bin/sh; b=0; while read p q r; do R[$b]=$r; b=`expr $b + 1`; done < ascii.txt ; echo "\n${R[@]}\n" ;` But this gives a message saying "Bad substitution" in line-9. Can help me with that? – Saumyen Kundu Mar 20 '21 at 20:39

0 Answers0