1

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.

Zoredache
  • 130,897
  • 41
  • 276
  • 420
user138770
  • 11
  • 1

3 Answers3

0

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 :)

Tom Newton
  • 4,141
  • 2
  • 24
  • 28
  • 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 08:14
0

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
Jay
  • 6,544
  • 25
  • 34
0

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.

jbsmith
  • 1,301
  • 7
  • 13