# Replace

### Replace

Replaces old value with new value in the input string @param old value, Type string. @param new value, Type string. Input must be a string.

Replace 'oldvalue' with 'newvalue' in the input string\
&#x20;                   @param oldvalue Type string \
&#x20;                   @param newvalue Type string\
&#x20;                    Input must be a string

This function allows users to replace or substitute a new string value in place of an old existing string value. This allows users to modify column values and add additional string values as per need and requirement&#x20;

### Example 1:&#x20;

Step 1: Create an empty **replace\_example** using AIOps studio as shown in the below screenshot.

![Empty pipeline 'replace\_example' created in RDA ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbokjFw-zUe7iW627Uk%2F-MbolO4TLBx0DFL_7lnj%2FScreen%20Shot%202021-06-10%20at%2012.14.11%20AM.png?alt=media\&token=ef452734-3216-4d18-a704-68b6f27bdac5)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (column)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### string format.`*\
*`##### Function 'replace' replaces old value with new value`*\
\
*`@dm:empty`* \
*`--> @dm:addrow id = '1' & category = 'Cluster-1' & value = 10`*\
*`--> @dm:addrow id = '2' & category = 'Cluster-2' & value = 101`*\
*`--> @dm:addrow id = '3' & category = 'Cluster-3' & value = 21`*\
*`--> @dm:addrow id = '4' & category = 'Cluster-4' & value = 30`*\
*`--> @dm:addrow id = '5' & category = 'Test-Cluster-5' & value = 500`*\
*`--> @dm:addrow id = '6' & category = 'Cluster-6' & value = 50`*\
*`--> @dm:map func = 'replace' & oldvalue = 'Cluster' & newvalue = 'CFX-Cluster' & attr = 'category'`*&#x20;

!['replace' pipeline code added](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MiQJLMe-JTQ9YlGi1Sm%2F-MiQKHCDCnA-T1bsicrf%2Fimage.png?alt=media\&token=e3b9e2b6-1caa-4ca0-9d06-0b005b3d2cbc)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies the replace pipeline code snippet](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MiQKkdS_1f7S5vrpwL_%2F-MiQL-DVaDlsRWJOY7lG%2Fimage.png?alt=media\&token=4bb261d8-117d-4659-a245-51c49cac16a0)

Step 4:  Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![RDA executes 'replace pipeline'  code snippet without any errors](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MiQKkdS_1f7S5vrpwL_%2F-MiQLJSNx9lOr0Ryd9RC%2Fimage.png?alt=media\&token=ca69d5b4-c7bc-4537-94e9-349685f69451)

Step 5: RDA uses the replace function to replace the old value with a new value for the selected column. Click on Verify to check replaced values as shown below.

![Replaced Values](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MiQKkdS_1f7S5vrpwL_%2F-MiQLv3C2PbzP4aWU8Yj%2Fimage.png?alt=media\&token=6506aabb-ab4b-4e61-9cc9-4927ba788534)

Simple Example - The following is a simple example of another example and final verify output where attribute 'column1' has a value of "Hello abc World" is replaced with "Hello CFX World" after successful execution of pipeline. Try this on your own (as shown below screenshot).

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MboqEOiKG4RxEARzqqI%2F-Mboq_aiR8BzGZ8xYd0j%2Fimage.png?alt=media\&token=8669c96f-c761-4488-adb8-f3d844102b1d)

### Example 2:&#x20;

This example provides a pipeline that uses the 'replace' function to replace a specific character within a string. This will be useful in case if a user wants to search and replace a special character or add additional tokens etc.

Step 1: Create an empty **replace\_char\_example** using AIOps studio as shown in the below screenshot.

![Empty 'replace\_char\_example' pipeline.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mbs3LIeOtb2fOirCWOS%2F-Mbs3vq16f8wDgliRcBG%2Fimage.png?alt=media\&token=c338cae5-edd6-456f-b81e-ea73b8680a3d)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (column)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### string format.`*\
*`##### Function 'replace' replaces char '"' with empty char ''`*\
\
*`@dm:empty`* \
*`--> @dm:addrow column = 'Hello " World'`*\
*`--> @dm:eval column = "column.replace(chr(34),'')"`*

*Note: Users can use this example to try other characters replacements and/or other character token replacements*

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mbs8_p8YNDtEGTqh-gN%2F-Mbs8wTX5PAuwwyKafsu%2FScreen%20Shot%202021-06-10%20at%204.00.22%20PM.png?alt=media\&token=e081b7b3-c6c7-4670-8e00-eafa706195ae)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies validation of pipeline syntax.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mbs8xVu9fDXMpOKYtyx%2F-Mbs9JIloq4T6bmracBZ%2Fimage.png?alt=media\&token=57cb97cc-a4af-4195-8c3c-bcf15b53780e)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Successful execution of above pipeline without any errors.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mbs9T7wb4oqHyyLDrrB%2F-Mbs9lsGJslJa3iLL_mM%2FScreen%20Shot%202021-06-10%20at%204.04.00%20PM.png?alt=media\&token=3b39b04c-d181-4d9b-a63d-e723ad41e1fd)

Step 5: RDA uses the replace function to replace a character from the string with an empty token and prints the output of the original string as shown in the below screenshot.

Old value --> **'Hello " World'**\
New value --> **'Hello World'**

![RDA uses replace function to replace a char in the string and replaces with empty token (space).](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsAjvwFDd9aVJ59mQ-%2F-MbsBd7RuHZxbDUmvmlH%2FScreen%20Shot%202021-06-10%20at%204.12.10%20PM.png?alt=media\&token=d8b67216-59dc-4a9b-b574-7a108dcb772d)

### Example 3:&#x20;

This example provides a pipeline that uses the 'replace'  function multiple times to search for a pattern that is repeated within a string and replace a common character separator or token within that string.

Step 1: Create an empty **replace\_multi\_char\_example** using AIOps studio as shown in the below screenshot.

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsFKU60x-NJkF2uVap%2F-MbsFMgfhdY4UT4W2Tqc%2FScreen%20Shot%202021-06-10%20at%204.28.14%20PM.png?alt=media\&token=40178e52-851e-49f4-8671-668e91a31d83)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (mac)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used twice to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### char format.`*\
*`##### Function 'replace' replaces char '| ' and '|' with ',' character`*  \
\
*`@dm:empty`* \
*`--> @dm:addrow mac = '001b 6384 45e6| 001c 4432 4467  000a 959d 6816|000a 959d 6816'`*  \
*`--> @dm:eval mac = "mac.replace('| ',',').replace('|',',')"`*

*Note: Example uses two patterns to replace special character or token with other tokens within the mac addresses*

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsLnD5-_upd0bldRk_%2F-MbsMPUXhA59iC_ryPbn%2FScreen%20Shot%202021-06-10%20at%204.59.07%20PM.png?alt=media\&token=028e6ade-3118-40aa-b0c4-e931bba1a10e)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies the pipeline code snippet for any errors](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsMZLwuNn5m-CBxI9A%2F-MbsMxLx8xooDfASxMd_%2Fimage.png?alt=media\&token=5bf5c53a-6255-4ede-b4e8-48016e846485)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsN3b9mLvY50Xk6TGT%2F-MbsNQv8brQjINkgny95%2Fimage.png?alt=media\&token=9b4a70a9-ae25-4de3-8ad8-5d7f125863cd)

Step 5: RDA uses the function 'replace' to replace multi-pattern character tokens, adds 'comma' as token, and returns the string after replacement as shown in the below screenshot.

![RDA 'replace' function replaces special pattern strings for replacement/substitution](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MbsNi3oOj8qjCmKoHbx%2F-MbsODvdPhCnTs7T805n%2FScreen%20Shot%202021-06-10%20at%205.07.09%20PM.png?alt=media\&token=6650626c-5bd7-4a68-95f9-a80a579d84ac)

In addition to the above-provided examples, users can use replace for any substitution of strings, special chars, within the pipeline context and store the data.

### Example 4:

This example provides a pipeline that uses the 'replace'  function when the column values have ’Cluster” as the name should add a prefix (e.g. Sub or other prefixes ). This will help users to replace or substitute a string value with custom strings or prefixes.

Step 1: Create an empty **replace\_prefix\_example** using AIOps studio as shown in the below screenshot.

![Empty pipeline  ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MdxPrJUu_DQxjStHpOh%2F-MdxQldhhes7eR0gkZcV%2FScreen%20Shot%202021-07-06%20at%201.07.40%20PM.png?alt=media\&token=803b16da-fe1b-43ab-abeb-3e2bf1311329)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates set of records that contains Cluster-x as value strings`*\
*`##### in the dataset.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses replace (substitute) column values that contain Cluster`* \
*`#####  with a prefix 'Sub' and adds it back`*\
*`##### Function 'replace' replaces old value (Cluster) with new value (Sub)`*\
\
*`@dm:empty`* \
*`--> @dm:addrow id = '1' & category = 'Cluster-1' & value = 10`*\
*`--> @dm:addrow id = '2' & category = 'Cluster-2' & value = 101`*\
*`--> @dm:addrow id = '3' & category = 'Cluster-3' & value = 21`*\
*`--> @dm:addrow id = '4' & category = 'Cluster-4' & value = 30`*\
*`--> @dm:addrow id = '5' & category = 'Test-Cluster-5' & value = 500`*\
*`--> @dm:addrow id = '6' & category = 'Cluster-6' & value = 50`*\
*`--> @dm:map func = 'replace' & oldvalue = 'Cluster' & newvalue = 'CFX-Cluster' & attr = 'category'`*

![Pipeline code added to empty pipeline window ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MdxTljWf4DG7N9o98qX%2F-MdxU02Fwkb_2BpuFO8Z%2FScreen%20Shot%202021-07-06%20at%201.21.57%20PM.png?alt=media\&token=76e24485-5f28-4965-aaa5-6b211386fd66)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![Verify the pipeline code by selecting 'Verify' button as shown above](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MdxUNEaouN9b2Lt7dq1%2F-MdxUeNKdCe927dAIqw2%2FScreen%20Shot%202021-07-06%20at%201.24.43%20PM.png?alt=media\&token=9dddc207-fbc5-4c0a-ac83-ae4b0d3f110f)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MdxUrEhdsib6cCqNUnR%2F-MdxVIC23rH6C2G3oA2w%2FScreen%20Shot%202021-07-06%20at%201.27.27%20PM.png?alt=media\&token=c2528620-61b8-43c8-8557-be9e21cfe3cb)

Step 5: RDA uses the function 'replace' to replace/substitute the 'Cluster' string with 'CFX' and returns the string after replacement as shown in the below screenshot.

![Successful execution of pipeline and replacement of the 'Cluster' string with 'CFX' prefix.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MdxVgaXBsW5Bv0GFEKR%2F-MdxW1UafTL3G6C2BuFJ%2FScreen%20Shot%202021-07-06%20at%201.30.46%20PM.png?alt=media\&token=8b17d392-3f10-41ba-b737-640ebbc5b09d)
