Page 1 of 1

Create sequential file only if any rows written into it

Posted: Wed Sep 30, 2009 2:05 am
by satheesh_color
Hi All,

We have a requirement to Create sequential file only if any rows written into it, otherwise no need to create a sequential file.

please let me know you thoughts on how to acheive this task.


Thanks,
Satheesh

Posted: Wed Sep 30, 2009 2:32 am
by ArndW
Instead of complicated workaround, put in an after-job call to SH and execute "find . -name {YourFileName} -size 0 -exec rm -f {} \;" . I am sure that the real UNIX experts will suggest a more efifacious command, but this should work well enough.

Posted: Wed Sep 30, 2009 2:45 am
by Sainath.Srinivasan
or you can create the file with a different name and copy it to your expected output name if the size is greater than 0.

Code: Select all

test -s
will assist you.

Posted: Wed Sep 30, 2009 2:46 am
by ArndW
I've only used "test -s" in scripts and don't know how it can be used in a single command line to delete zero length files, which is why I reverted to the time-honored and much distinguished "find" command. Do you have an example of how to use "test" without writing or calling a script?

Posted: Wed Sep 30, 2009 5:21 am
by chulett
Bottom line, Satheesh, is that your sequential file will always be created regardless of how many records are written to it, including zero. So you will either need some kind of 'work around' to fake this (as posted) or just live with and don't worry about it (which is what practically everyone does).

Posted: Thu Oct 01, 2009 2:00 am
by satheesh_color
Hi,

Thanks for your feedback on this. We made a decision to overwrite the file everyday irrespective of number of records.


Thanks,
Satheesh

Posted: Thu Oct 01, 2009 3:28 am
by Sreenivasulu
You can use the 'touch' command as well

Regards
Sreeni