Update file record inside read loop

Hi,
I am reading file records inside a while loop,
and want to update the record when certain condition is met.
How can I update a file while being read?
I want to avoid using temporary files, copy, rename, ...

while IFS=',' read -r f1 f2
do

  function(f1,f2)
  if [ $? -eq 1 ]
  then
     <add field 'ok' as 3rd field to this record in the file>
  fi

done < ${INPUT_FILE}

Thanks,
-sri

Not really, no. There is no seamless 'insert' operation for a file. To add extra data to the middle of a file, you must rewrite all the data that comes after it. That is why inserting data is so complicated, you never really do so.

The usual solutions for doing it all in one step, ed or sed -i, still use a temp file in many implementations.

So, since your records aren't fixed-width, the answer is no. If they were fixed-width, you could change any record without changing the length of the line, making it more possible, but fixed-width records are a difficult thing to handle in shell!