If you want to find certain words, patterns or characters and replace them in a text file, you can use Find and Replace in Text file instruction.
In this article, we will go through the different ways you can use the Find and Replace in Text file instruction.
Find and replace. Text mode
| Choose this mode of the file instruction if you need to replace a known string with another string. |
1. Create a file instruction of type "Find and Replace in Text".
2. Link a text file you want to change to the instruction.
3. In the "Settings" section choose "Text" option. Specify whether your search is case sensitive or not by checking the box.
4. Specify the text you want to find and what you want to replace it with in the "Replacement rules" section.
5. To test your rules you can input a sample string to the texting box and check the output result.
6. Save the step.
Find and replace. Escape mode
| Choose this mode of the file instruction if you need to replace special characters with text or other characters. |
1. Create a file instruction of type "Find and Replace in Text".
2. Link a text file you want to change to the instruction.
3. In the "Settings" section choose "Escape" option. Specify whether your search is case sensitive or not by checking the box.
4. Specify the text you want to find and what you want to replace it with in the "Replacement rules" section.
In the example below, we are trying to replace all new lines with a comma and a space.
5. To test your rules you can input a sample string to the texting box and check the output result.
6. Save the step.
Supported characters:
\n The Line Feed control character LF (ASCII 0x0A);
\r The Carriage Return control character CR (ASCII 0x0D);
\t The TAB control character (ASCII 0x09);
\\ The literal backslash character (ASCII 0x5C);
\xNN The hexadecimal representation of a byte, made of 2 digits in the 0-9, A-F/a-f range. For instance, \x20 is the space character;
\uNNNN The hexadecimal representation of a two-byte character, made of 4 digits in the 0-9, A-F/a-f range. For example, \u263A is the ☺ character.
Find and replace. Regex mode
| Choose this mode of the file instruction if you need to replace a string that can be found by a specific pattern. |
1. Create a file instruction of type "Find and Replace in Text".
2. Link a text file you want to change to the instruction.
3. In the "Settings" section choose "Regexes" option. Specify whether your search is case sensitive or not by checking the box.
4. Specify the character or set of characters you want to find and what you want to replace it with in the "Replacement rules" section.
In the example below, we are trying to clean up emails formatting in a file by applying a pattern to find all available email representations and replace it with just an email.
5. To test your rules you can input a sample string to the texting box and check the output result.
6. Save the step.
Supported regex:
This mode supports regex pattern and replacement notation according to Regular Expression Language - Quick Reference - .NET and
Substitutions in Regular Expressions - .NET accordingly.
Comments
0 comments
Please sign in to leave a comment.