Originally posted by: The_Doctor
As previously stated, this is a classic race condition between 2 different processes, giving unpredictable results.
The "cat" process is forked. The "rm" process is forked. These 2 forked processes run asynchronously.... not serially.... thus the unpredictable results.
Change your code to remove the reliance on "rm" & "touch" and you'll be good to go. aka.... there are many ways to do accomplish what you want without "rm" & "touch".
BTW....
your use of echo makes sed redundant. You can remove the pipe to sed & speed things up dramatically. Like I said.... many ways to do it, here's but one example:
#!/bin/ksh > temp.txt # ensure our temp file is empty
while read File_Line
do echo $
{File_Line
} >> temp.txt # sed
's/ *$//g' ..... the string passed to sed is redundant # remove the pipe to sed and # avoid the fork of a
new sed process
for every line in the file # 1,000,000 lines = 1,000,000 forks = slow done < file.txt # or use the cat | format
if you don
't like this mv temp.txt file.txt # destroy original file
if you wish
#AIX-Forum