Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

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

Your Answer


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.