For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2005 > how to truncate an output file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to truncate an output file
Kevin Rodgers

2005-02-16, 8:56 am

I'm writing a program that splits the input stream into multiple output
files, whose names are determined at run time. At the point where the
program starts writing to a "new" output file, I want it to truncate the
file (in case it already exists). I thought this would do the trick,
but it initializes the file to 1 byte (the newline character):

{
outputfile = "something_that_depends_on_" $0
printf "" > outputfile
}

What's the right way to accomplish that?

Thanks,
--
Kevin Rodgers
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com