Create sequential file only if any rows written into it

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
satheesh_color
Participant
Posts: 182
Joined: Thu Jun 16, 2005 2:05 am

Create sequential file only if any rows written into it

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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).
-craig

"You can never have too many knives" -- Logan Nine Fingers
satheesh_color
Participant
Posts: 182
Joined: Thu Jun 16, 2005 2:05 am

Post 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
Sreenivasulu
Premium Member
Premium Member
Posts: 892
Joined: Thu Oct 16, 2003 5:18 am

Post by Sreenivasulu »

You can use the 'touch' command as well

Regards
Sreeni
Post Reply