Need to find and replace on a text file

Hello!

I need to find and replace on a text file (a json file actually), which activities should i use?

I need to remove the “]”

and insert the below:

{
“email”: “variable1”,
“region”: “variable2” }
]

Can someone help?

Hi @andrea.venturino

Use the read text file activity and the output of that activity will be a string variable for example consider the variable as str_Json.

Use the below syntax to replace the ]

str_Json.Replace("]","")

Regards

Thank you @vrdabberu .

I do not have the “assign” activity.

This is what i am trying to achive:

  1. write the string
  2. read the file
  3. replace “]” with the string of point 1

Hi @andrea.venturino

Yes that’s correct.

Regards

HI @andrea.venturino

As you are using StudioX i have created a workflow in StudioX only please check below:

Regards

For some reason is no updating the file. Any idea of why?

Hi @andrea.venturino

If you want to write the data back to text file then please write the data to a new text file by using the Write Text activity. Please note that the modified data need to be written in a new text file.

If you wanted to write back to the same file the use the below workflow:
For writing to the same text file you need to delete the file because the write text file will helps in overwritting the data so whatever the excess data is there in file it will remained same so before using the write text file make sure that you have deleted the existing text file.

Regards

Thank you @vrdabberu .

I am probably going the wrong way.

Do you think this activity can be achived as follows:

Hi @andrea.venturino

Find and replace also works on the data directly but not on the text file. If you want to have the replaced data in text file then please use the above steps.

Regards

Thank you a lot @vrdabberu

Hi @andrea.venturino

I hope you found the solution for your query. If yes, please mark solution to close the loop or else please let me know i’m happy help if you have any query.

Regards

hi @vrdabberu

yes the issue is resolved, i have a last minute question: do you think that the robot could also work with the following process:

  1. read file
  2. delete the ]
  3. append the new string of text?

Hi @andrea.venturino

  1. Read file will be worked.

  2. Delete ] means there will be remove and replace function can be done. In remove you need to know the excat position but while in replace where ever the ] may be you can simply replace them with nothing so in this way also the ] can be neglected.

  3. append is the activity which helps to add the new data to the exisiting file but in your case you need to remove ] in text file so please use the write text file activity only either by deleting the existing file and writing the data to the same file or else by writing the modified data to the new text file.

For better understanding please check the above replies I have given the detailed workflow.

Regards

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.