User Tools

Site Tools


output_to_file_issues

If you want to send us your comments, please do so. Thanks
More on comments


Output to file issues

In awk this does not work. Not in the BEGIN part nor in the main loop

print "Test" > /tmp/file.txt
print "Test" >> /tmp/file.txt
print "Test" > /tmp/file.txt

The contenst of /tmp/file.txt is

Test
Test
Test

Although the expected output is

Test

Since with the second > it is expected that the file is clearrd and started over again empty.

This is a problem when every record needs its own file.

Workaround

Add when the file has to be started over empty

system("rm /tmp/file.txt")

This does not work. awk can not find the file any more. Soo add

system("touch /tmp/test.printtofile.txt")

Now the file is there but awk does not recognise it.
However it can be solved by using

close("/tmp/file.txt")
printf("") > "/tmp/file.txt"
open ("/tmp/file.txt")

Now the file is empty.
So in fact now > and » can be used in a way in awk


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
output_to_file_issues.txt · Last modified: 08-08-2015 23:33 by wim