Skip to content
Advertisement

awk in non-interactive is leaving some data missing

I’m running an awk command in a shell script, and it’s breaking the datafile. All of the data doesn’t load, and there’s a newline character at the end of each line.

JavaScript

If I run this as a command, it works perfectly.

I’ve just found that i can use fflush() and it seems to have solved the issue.

So now i have:

JavaScript

Am I setting myself up for disaster?

Also, the file is renamed to $filename.locked.concur0 — I’m guessing this zero is the exit code that’s returned from fflush? How do I get rid of this 0?

full code:

JavaScript

Advertisement

Answer

the problem is indeed that you are reading from and writing to the same file. this should work better:

JavaScript

better still:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement