Appending file in the read mode.

I have situation, wherein while reading the file, I intend to write the same file & loop ahead until the end of file.

Problem I am facing is I can only read the file. Like ...

cat file | while read row; do
....
done

So if I write anything to this file within while block, is not read within this same while loop.

Is there any way, or construct so I can achieve Append the file during read process?

cat file | while read row; do
....
done >> file

Say initially file has values like :

A
B

If I append the same file with values :
C
D

Then I expect it will loop A, B, C, & D values. Though it is appending to the same file, it is not looping values C & D.

It is something like in JAVA, you have data structure as vector. You can iterate & populate at the same time. So in iteration, you can as well iterate the recently added value.

this should iterate the recently added value. but make sure that you add a condition in the while loop to exit or else it might go to infinite loop. Might be you could add a counter variable to exit after running the loop for specific number of times.

while read fname ; do
echo x >>$filename
 done <$filename

Great, seems working. Thanks Ahmed.