Would like to not create an empty csv file

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: No create csv empty

Post by SURA »

PAULOM wrote:when it's empty (only column name present), is it possible?
Hi Guys

Is this is really a 0 size file?

I think, head -2 | wc -l should be > 1
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

chulett wrote:Well, heck, of course - the z modifier! Why didn't I think of that?

:P
Actually I believe the correct terminology is the "z specifier".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sura's intervention raises the possibility of needing to handle the possibility that "first line is column names" is asserted, in which case an "empty" file will contain one line. The usual technique in a DOS batch file is to count the line terminators.

Code: Select all

set file=textfile.txt
set /a cnt=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a cnt=%%a
echo %file% has %cnt% lines
Of course, instead of echo in the last line, you'd perform a test and delete %file% only if %cnt% <= 1.

A couple of techniqes (tricks?) with the FIND command:
  • Running the FIND command with option /v and empty search string will find all lines.

    Running the FIND command with option /c will output the line count only.
The FOR command with /f option will parse the string, in this case extracting the line count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
PAULOM
Participant
Posts: 33
Joined: Thu Jul 11, 2013 2:03 am

Post by PAULOM »

Like my csv have "first line is column names", the size of files = 300 o

As I did not succes to make it with after-job subroutine, I try to do with a Sequence whit "Execute Command" :

IF EXIST \myfolder\ test.csv del /F /Q \myfolder\ test.csv

But for the size less than 300o, i don't know, please help.

Thanks guys


Ray.Wurlod : I do not manage to read completely your messages -->Premium content
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Learn about membership benefits and get premium membership here.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
PAULOM
Participant
Posts: 33
Joined: Thu Jul 11, 2013 2:03 am

Post by PAULOM »

Why it's only for your message?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Because all of your answers are contained within them?
-craig

"You can never have too many knives" -- Logan Nine Fingers
PAULOM
Participant
Posts: 33
Joined: Thu Jul 11, 2013 2:03 am

Post by PAULOM »

Anybody has an alternative?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Google. Seriously, DOS commands and 'tricks' are well documented out there in the wild and it shouldn't be hard to find multiple discussions on how to (for example) count file records in a DOS batch. Or check a file's size. Or whatever you need. That's what I would have done in your shoes.
-craig

"You can never have too many knives" -- Logan Nine Fingers
PAULOM
Participant
Posts: 33
Joined: Thu Jul 11, 2013 2:03 am

Post by PAULOM »

I don't want a batch but one command DOS for the size...

But well it's not serious I will untangle.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not sure there's a "one command" DOS solution. Do you have the MKSToolkit installed with your product? If so you have UNIX-like commands at your disposal and those can certainly be one shot.
-craig

"You can never have too many knives" -- Logan Nine Fingers
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Post by SURA »

If you understand it will be simple.

There is no single command to do that. But you can google it and find good number of code.

If you don't want dos then write shell script. This will be a simple code like English !
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you had a premium membership you would have at least two solutions already. I posted complete solutions.

The funding model for DataStage - what keeps it alive - is premium membership (notice the lack of advertising?). There are five identified "premium posters" - acknowledged experts whose advise is considered to be valuable enough to charge for. But it's not a lot - less than $0.30 per day.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
PAULOM
Participant
Posts: 33
Joined: Thu Jul 11, 2013 2:03 am

Post by PAULOM »

I found this :

for /F "delims=" %A in ('dir /b *.csv') do if %~zA LSS 1024 del "%~dpnxA"
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And? Is that working for you?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply