Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


DanAnderson
2015-10-20T18:46:05Z
Based on a line item delimiter, I need to split one text file into many different text files. Does Visual Cron provide the functionality to accomplish this?
Sponsor
Forum information
ErikC
2015-10-21T07:37:10Z
Hi Dan,

As there is no dedicated task to do so, you could use the .NET code execute task to do this.

Read the file, and do a foreach on the split chunks and write them all to a seperate file.
This method uses some parameters like the source filename and maybe the delimiter text, so you could reuse the method.
Sounds easy right? Hope you can do some .NET yourself....😕

Regards,
Erik


Uses Visualcron since 2006.
Luke Saunders
2015-10-28T18:33:55Z
You could also install gnuwin32 unix utilities for windows and get access to the unix split command which is designed to do exactly what you need, which you could then schedule in visual cron.

http://sourceforge.net/projects/getgnuwin32/ 
Support
2015-11-02T10:26:33Z
We will probably create a Task for this soon. Please let us know all features you want. I will now move this request to Feature request forum.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
jsmisek
2015-11-17T14:20:58Z
I use Powershell to split by line. This may or may not work for you. I did not make this script myself but have found it very useful.

Quote:


#############################################
# Split a log/text file into smaller chunks #
#############################################
#
# WARNING: This will take a long while with extremely large files and uses lots of memory to stage the file
#

# Set the baseline counters
#
# Set the line counter to 0
$linecount = 0
# Set the file counter to 1. This is used for the naming of the log files
$filenumber = 1

# Prompt user for the path
$sourcefilename = Read-Host "What is the full path and name of the log file to split? (e.g. D:\mylogfiles\mylog.txt)"

# Prompt user for the destination folder to create the chunk files
$destinationfolderpath = Read-Host "What is the path where you want to extract the content? (e.g. d:\yourpath\)"

Write-Host "Please wait while the line count is calculated. This may take a while. No really, it could take a long time."

# Find the current line count to present to the user before asking the new line count for chunk files
Get-Content $sourcefilename | Measure-Object | ForEach-Object { $sourcelinecount = $_.Count }

#Tell the user how large the current file is
Write-Host "Your current file size is $sourcelinecount lines long"

# Prompt user for the size of the new chunk files
$destinationfilesize = Read-Host "How many lines will be in each new split file?"

# the new size is a string, so we convert to integer and up
# Set the upper boundary (maximum line count to write to each file)
$maxsize = [int]$destinationfilesize

Write-Host File is $sourcefilename - destination is $destinationfolderpath - new file line count will be $destinationfilesize

# The process reads each line of the source file, writes it to the target log file and increments the line counter. When it reaches 100000 (approximately 50 MB of text data)
$content = get-content $sourcefilename | % {
Add-Content $destinationfolderpath\splitlog$filenumber.txt "$_"
$linecount ++
If ($linecount -eq $maxsize) {
$filenumber++
$linecount = 0
}
}

# Clean up after your pet
[gc]::collect()
[gc]::WaitForPendingFinalizers()

Scroll to Top