Replace
Previous  Top  Next

Replace is used to read a file line by line and replace any series of characters, spaces or words (what programmer's call "strings") with another string. For instance, replace can be used to replace every instance of "buy to cover" with "buy". Here is such a command:

replace|inputfile.txt|outputfile.txt|buy to cover|buy

Spaces can be used as the replacement text, and the command is performed repetitively on a line until no more instances remain in the line. For instance, the following script command replaces instances of multiple spaces, reducing them to single spaces. Sometimes brokerages may have fields broken up by varying numbers of spaces between different fields. Because the command repeats over the line, by putting only two spaces in the field of text to be replaced and a single space in the last field, all of the varying spaces will be reduced to a single space. Here is such a script command:

replace|inputfile.txt|outputfile.txt| |

Note: it may be hard to see in the example, but there are two spaces in the field following the outputfile.txt and a single space trailing at the very end. The two file names can, of course, be any names chosen by the user.