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.


Mark Johnson
2008-07-30T22:20:47Z
Support,

Is it possible to use the variable String.Replace function to find strings in a file and replace their values?

Here is what I am trying to do.

I want to read a .txt file and anywhere in the file where the word “HEAD” is used to replace it with “Head”. Can I do that using the variables? If so, how would I format the variable? Could you please give me an example?

Thanks
Mark
Sponsor
Forum information
Support
2008-07-30T22:26:59Z
You can do it the following way:

1. Create a Job
2. Add a File Read Task and save the Job
3. Add a File Write Task and use Variables window to point out the previous Tasks output. Sorround that Task with a replace function. You put this value in the Value property of the File write Task. It could look something like this but you need to point out your own previous Task so the Id of the Task is correct:

{STRING(Replace,{TASK(0261600e-b14b-436d-9722-ef1bff5c69c3,StdOut)}"HEAD","Head")}
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Mark Johnson
2008-07-30T23:00:40Z
Henrik,

Thank you. I was able to get it to work. Here is what my string looks like:

{STRING(Replace,{TASK(bd572941-6582-4b9e-b5cd-0d3e571b3326,StdOut)},HEAD,Head)}

Now, can I do a find and replace on more then one string in the same write task? I need to find and replace "HEAD", "ITEM" & "TOTAL", with "Head", "Item" & "Total".

Thanks for your help.

-Mark
Support
2008-07-30T23:18:31Z
Ok,

Variables can replace up to 3 levels. In this case, to make it more clear, I would Create a Variable first in the Variables editor. Then set the Variable with Set Variable Tasks. Something like this:

Tasks
1. Read File Task
2. Set Variable (replace1)
3. Set Variable (replace2)
4. Set Variable (replace3)
5. Write File Task (write your own Variable)
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
ErikC
2008-07-31T08:19:04Z
So you have to put the whole output of task 1 in a string user variable and use task 2-4 to change that variable with the replace function. In task5 you with the variable back to a file.
Uses Visualcron since 2006.
JZatulove
2008-07-31T15:40:55Z
Mark,

Not to dismay the use of visualCron, but you might be bending it a little more than its intended purpose of managing the task, not doing the task.
If you find yourself having to do tasks like this, you should look into scripting languages that handle regular expressions (find/replace text by matching patterns). They're very powerful and for a small task like this very manageable and customizable, you would be dealing with one line of code.
Perl or Python would be the place to start.

http://www.perl.org/get.html 
http://www.python.org/download/ 
Mark Johnson
2008-07-31T16:33:05Z
I probably will use Perl to do this find and replace. I use Perl and DOS Batch scripts to handle other tasks outside the scope of VC, and this seems like a good task for Perl.

Each App has it's strong points.

Thanks

Mark
sborer
2010-10-01T11:05:56Z
Hi everybody,

i have another question in case of "search and replace".

is it possible to get a list of files in a directory, go trough this, like a "for loop" and search and replace Var1 with Var2 in every single file?

Thanks & kind regards
Sven
Support
2010-10-01T11:21:04Z
sborer wrote:

Hi everybody,

i have another question in case of "search and replace".

is it possible to get a list of files in a directory, go trough this, like a "for loop" and search and replace Var1 with Var2 in every single file?

Thanks & kind regards
Sven



Not yet. You want to go through a number of files and just replace text? (normal text files)
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
sborer
2010-10-01T11:57:01Z
Support wrote:

sborer wrote:

Hi everybody,

i have another question in case of "search and replace".

is it possible to get a list of files in a directory, go trough this, like a "for loop" and search and replace Var1 with Var2 in every single file?

Thanks & kind regards
Sven



Not yet. You want to go through a number of files and just replace text? (normal text files)



yes, exactly this .... isn't that possible yet?
Support
2010-10-01T12:51:47Z
sborer wrote:

Support wrote:

sborer wrote:

Hi everybody,

i have another question in case of "search and replace".

is it possible to get a list of files in a directory, go trough this, like a "for loop" and search and replace Var1 with Var2 in every single file?

Thanks & kind regards
Sven



Not yet. You want to go through a number of files and just replace text? (normal text files)



yes, exactly this .... isn't that possible yet?



No, we have thought about this. Please add that as a Feature request in the Feature requests forum and we will update you when we have something.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top