Creating temporary file names 
Author Message
 Creating temporary file names

Hello all,

How do you create unique temporary file names from within an awk
script.  In the shell, I would write something like
'tmpfile=/tmp/tmp$$', and use the shells $$ variable to insert the
process ID.

At the moment, I either pass the name of the temporary file to the awk
program '-v temp=/tmp/tmp$$' say, or do some horrible hack involving
parsing the output of the 'ps' command from within the script itself.

Are there any better ways of generating unique temporary file names?

Is there an awk system variable (eg. PROCESS_ID) which would contain
this value (I'm pretty sure there isn't one in the SCO awk I use).

Is there such a variable in any version of awk (eg. gawk)?

Does the panel think that such a variable might be a good idea for a
future version of awk?

Thanks for any info,
--
Steve



Sun, 22 Apr 2001 03:00:00 GMT  
 Creating temporary file names
Normally, a method to guarantee uniqueness is to use a time stamp possibly
concatenated with machine name or user name or both. I have read in other
postings that there are some time functions in certain versions of awk
(sorry I'm not familiar with any of them) but you can always use getline in
conjunction with the system command which returns the time and read it from
there. In such a scenario, you can also assign the PID as you yourself
suggested.

However, if the file is temporary, you can also use a constant name and then
just delete the file in the BEGIN portion of the awk program using
system("rm tempfile"). For real portability, you can probably just use a
printf "" >"tempfile" (also in the BEGIN) so that your program will run on
systems where "rm" is not the command to remove a file. I'm just not sure
how long the "temporary" file must stay on your system. If it's once per
iteration of the program, then this is OK but if you need to keep daily logs
for a monthly period (as an example) then this will not do.

Hope I've helped.

Cesar
--
Please remove the UPPERCASE characters from my e-mail address for the real
thing

Quote:

>Hello all,

>How do you create unique temporary file names from within an awk
>script.  In the shell, I would write something like
>'tmpfile=/tmp/tmp$$', and use the shells $$ variable to insert the
>process ID.

>At the moment, I either pass the name of the temporary file to the awk
>program '-v temp=/tmp/tmp$$' say, or do some horrible hack involving
>parsing the output of the 'ps' command from within the script itself.

>Are there any better ways of generating unique temporary file names?

>Is there an awk system variable (eg. PROCESS_ID) which would contain
>this value (I'm pretty sure there isn't one in the SCO awk I use).

>Is there such a variable in any version of awk (eg. gawk)?

>Does the panel think that such a variable might be a good idea for a
>future version of awk?

>Thanks for any info,
>--
>Steve



Sun, 22 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Temporary file names (was: CW15 : Freeware library)

2. Temporary file names (was:

3. Temporary file names

4. Temporary File Name and FTP

5. temporary file names

6. temporary file name?

7. Creating a temporary file for reports

8. create temporary files?

9. creating temporary files

10. Temporary files not getting deleted (or created!)

11. Creating temporary files

12. newbie - creating temporary files

 

 
Powered by phpBB® Forum Software