Task to Count Characters in a text file - VisualCron - Forum

Community forum

Is there a task that would look at a text file and then count the characters? I need to produce a text file with a header that shows not only the record count but character total.
That sounds like a pretty specific need.
It would be pretty easy to write a program to do that, and just use an execute task.
Or, use a vbscript or powershell script to do it from an execute script task.

(Couple example scripts here: http://www.computing.net...haracter-in-a/19751.html )
Unfortunately i am programming iliterate and just thought there was a solution using Visual Cron...I am not worried about the header info...just the character count...i would take the output from the script and use it within my project which is being built within SQL SSIS 2008. Thanks for the reply though.
Hi klewis10367,

I did some Googling and I found a utility that can do the task for you:

WordCount - Character, word and line counter 

Use it like this in an execute task: wc -c [filename]

Uses Visualcron since 2006.
Thanks for that, but for my purposes i need something that will either export the count to a text file or if run within an SSIS package use the count in a variable as i need to incorporate that number in another text file.
Hi klewis10367,

I believe I can help you out here.
The output of the program can be written to a file with the file write task using the output variable of the execute task.
Or you can use the wc program with parameters like '-c file2count.txt > outfile.txt' to have the output already in a file outfile.txt.

Within SSIS you can open this file and using a split meganism you can extract the character count.

You can also use SSIS to open the file2count.txt and count the characters there. there is a .NET script component so you can do whatever you want.

Good luck,
Uses Visualcron since 2006.
Erik,thanks i will try... I was originally looking at SSIS but i did not see the .net Script Component...i was googling to try and find a vb script and then implement it in SSIS using the Script task. Can you point me in the direction of what .net component to use? i use SSIS quite a bit but when it comes to using the programming components i am ignorant.
Thanks...used the wc approach..have this as a batch file, which i will use Visual Cron to call

cd c:\
wc -C sl_GalaxyDataworks.txt>test.txt

My output is like this:

sl_GalaxyDataworks.txt: Chars: 242

The question is, is there a way to have the output be delimited by space where the character count would be its own column?

I will give you your number in the output, so you can use a file write task to make a file containing only this number:

FOR /F "eol=; tokens=3 delims= " %i in ('wc -c sl_GalaxyDataworks.txt') do @echo %i

You have to use this with the execute command:

command: cmd.exe
parameters: /c FOR /F "eol=; tokens=3 delims= " %i in ('wc -c sl_GalaxyDataworks.txt') do @echo %i

If the filename differs, you can use a variable here.

[EDIT]If you add ' > charcount.txt' to the parameters at the end, you already have a file so you do not need to use a file write task anymore[/EDIT]

Uses Visualcron since 2006.
Scroll to Top