I have a big c file that gives a lot of output that I don't care about right now. I wrote this awk script to do mostly what I want. Not sure how to put the finishing touches on it. I would also like it to write to a file when it gets the appropriate condition as true. Is this possible with awk? Or do I need to use a different program?
./a.out 50 5 4 |
awk '{
if ($1 =="success")
{
print "success";
print $3;
//write to success file
}
if ($1 =="failure")
{
print "failure";
print $3;
//write to failure file
}
if ($4 =="page")
print "page";
//write to page file
}'
Even if success , failure , page , and file are variables that contain strings consisting of decimal digits, <period> is not an operator in awk that can be used to join two strings. The names of files used in print output redirections have to be strings or variables that expand to non-empty strings.
I would guess that the request was for something more like:
If you have a script that wants to write to several files (typically, more than nine), you may have to worry about closing and reopening files and considering whether you want to append to existing files or overwrite them if you need to reopen an output file; but for just three output files, you don't have to worry about that.