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.


Richard Martin
2017-06-14T12:20:34Z
I have a text file generated from another system. with data as such
total.email.routed = 15
total.email.failures = 1
total.messages.dead = 5
total.users.active = 6

I'm able to get visual cron to read the file, and the entire file content is show in the output, therefore I know I can set a variable to the entire output.

What I'm trying to do, is assign a variable to be the value of "total.messages.dead", meaning how could I loop through the file, search each line for "total.messages.dead =", when that is found, remove everything before the equal symbol, so that my variable gets the value "5"

I've been at this for a day now, and not getting anywhere.
Sponsor
Forum information
thomas
2017-06-14T13:17:22Z
You can read the file, create a loop that goes through each line. Then write line to job variable if condition is met ( ie string contains messages.dead).

I find it cumbersome to do looping for tasks like this. A .Net task is much easier, and can be reused for similar tasks.

job.PNG

net.PNG

Support
2017-06-14T14:16:53Z
Yes, a small script would do this best.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Gary_W
2017-06-15T13:21:53Z
The read file task reads the entire file in to memory, accessible via the previous task STDOUT (at least that's the way it makes sense to me). Think of it like reading the entire file as a giant multi-line text blob.
The next task then should be a set job variable task, where you use a regular expression to set the value. As long as only one line has the pattern you seek, this should do it as the regex will look at the entire output from the read file at once (remember, it's a giant multi-line text field really):

{REGEX(Replace|{TASK(PrevTask,StdOut)}|(.*\s)*total.messages.dead = (\d*)(.*\s)*.*$|$2)}

The regex says to search through the previous task's StdOut (the entire file contents) for zero or more groups of characters followed by whitespace (lines ending with carriage return/linefeeds), followed by "total.messages.dead = ", followed by a captured group (in parens) of zero or more digits (the value we want to keep), followed by zero or more groups of characters followed by whitespace (lines ending with carriage return/linefeeds), followed by zero or more characters until the end of the file is reached. Then that string is replaced by the contents of the second captured group, referenced by the "$2".

So using your example data, the job variable will end up with a value of '5'.

Richard Martin
2017-06-19T19:05:07Z
Thanks everybody... Although still not working, I now have some solutions I can lookup, and research... This is exactly what I was looking for.
Gary_W
2017-06-19T19:25:00Z
My example worked with a file containing your example lines. Whats not working for you? Does your file contain more than one occurrence of the value you are after?
Scroll to Top