Page 2 of 4

Re: No create csv empty

Posted: Thu Aug 01, 2013 8:55 pm
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

Posted: Thu Aug 01, 2013 10:24 pm
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".

Posted: Thu Aug 01, 2013 10:41 pm
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.

Posted: Fri Aug 02, 2013 3:54 am
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

Posted: Fri Aug 02, 2013 5:19 am
by ray.wurlod
Learn about membership benefits and get premium membership here.

Posted: Fri Aug 02, 2013 6:34 am
by PAULOM
Why it's only for your message?

Posted: Fri Aug 02, 2013 7:15 am
by chulett
Because all of your answers are contained within them?

Posted: Fri Aug 02, 2013 7:42 am
by PAULOM
Anybody has an alternative?

Posted: Fri Aug 02, 2013 7:47 am
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.

Posted: Fri Aug 02, 2013 8:44 am
by PAULOM
I don't want a batch but one command DOS for the size...

But well it's not serious I will untangle.

Posted: Fri Aug 02, 2013 9:17 am
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.

Posted: Fri Aug 02, 2013 2:48 pm
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 !

Posted: Fri Aug 02, 2013 3:10 pm
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.

Posted: Mon Aug 05, 2013 4:05 am
by PAULOM
I found this :

for /F "delims=" %A in ('dir /b *.csv') do if %~zA LSS 1024 del "%~dpnxA"

Posted: Mon Aug 05, 2013 6:28 am
by chulett
And? Is that working for you?