Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am working on ETL job where we have used the below command to get the File names from the folder and it will also count the rows for each file.

exec( '/usr/bin/ksh', '-c "cd [$PFileDir];/usr/bin/wc -l [$PFileName] > [$PFileDir]/ETL_FILE_LIST"',2);

Now, I want the same functionality in Windows command, and not sure how to do it.

Any help will be highly appreciated.

share|improve this question
add comment

3 Answers

one of the first things you'll need is the tool "wc" which is being used to count rows - its in the textutils package and can be found here http://gnuwin32.sourceforge.net/packages.html

I would suggest you convert this to a dos batch file - you don't need to execute a shell (the /usr/bin/ksh bit) at the start, all you need to do is call wc -l on the right file, and send the output to where it used to go.

Suspect the best way is to start from scratch, play with wc on the commandline, get used to it, then build your own command up. Looks like you will be using some more batch scripting, so im not planning to teach you here :)

share|improve this answer
    
All wc -l does is count the number of lines in a file. I don't know Windows, but I can't imagine you need to download something just to do that. –  Jay Sep 27 '12 at 22:07
    
TBH I'm a linux man - if there's a gnu tool to do it, i'd rather have that. Windows isn't famed for its wealth of decent commandline tools ;) –  Tom Newton Sep 28 '12 at 8:14
add comment

I will give you half an answer:

exec( '/usr/bin/ksh', '-c "cd [$PFileDir];/usr/bin/wc -l [$PFileName] >  [$PFileDir]/ETL_FILE_LIST"',2);
^^^^^^^^^^^^^^^^^^^    ^   ^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  launch a shell       |   change directory   count the number of lines    write it to $PFileDir/ETL_FILE_LIST
                   run a command              in $PFileName

That's all this does. All you need to do is find a Windows equivalent to:

  • Change directory
  • Count the number of files in a line
  • Write the output somewhere
share|improve this answer
add comment

If you're running a recent version of Windows, then PowerShell should be built in. You should be able to get want you want with something like this:

ls $PFileDir -Recurse -File | %{"{0} {1}" -f $_.Name, ((Get-Content $_.FullName | Measure-Object).Count)} >> (Join-Path $PFileDir 'ETL_FILE_LIst')

The key is using Measure-Object to replace 'wc' as the line counter. Please see this Scripting Guy article for more details.

share|improve this answer
    
Thank you very much.. –  user138770 Oct 1 '12 at 20:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.