Skip to content

TSTool / Command / TextEdit


The TextEdit command edits a text file, currently providing simple search and replace for literal strings.

In the future this command may be enhanced to add the following features:

  • edit an in-memory property value containing text
  • allow multiple operations in one command

The search and replace functionality is implemented using Java pattern matching and regular expressions (see Pattern class documentation). It can be complicated to deal with special characters and patterns as they are processed through TSTool commands and underlying Java code. For example, some patterns pass through to the underlying code without changes whereas others need to be transformed or "escaped" to protect from manipulation by TSTool. The following examples illustrate how to perform common search and replace tasks.

The ReadPropertiesFromFile command can be used to read one or more properties from a text file and the property values can be used to replace text in an initial file.

Search and Replace Examples

SearchFor                                       ReplaceWith                                         Description
\r\n \n Replace Windows end of line with Linux end of line.
\n \r\n Replace Linux end of line Windows end of line with Linux end of line.
StationId \$\{StationId} Replace the static string StationId with a property ${StationId}. The dollar sign has special meaning to the pattern matcher (end of line) and braces also have meaning. Additionally, using ${ directly causes TSTool to try to replace with a property value. Using backslashes in front of the first two characters in the ReplaceWith parameter allows the string to pass through TSTool and pattern matcher without interpretation.
Some.*Text SomeNewText The * typically cannot be used alone and therefore .* indicates "any character followed by one or more characters". The example shows how intervening characters in the original string can be replaced with new text.
SomeFile\..*\.ext SomeFile\.ABC\.ext Similar to previous example except escape the period from interpretation by pattern matcher and treat literally, needed when handling filenames with extensions.

Command Editor

The following dialog is used to edit the command and illustrates the command syntax.


TextEdit Command Editor (see also the full-size image)

Command Syntax

The command syntax is as follows:


Command Parameters

Parameter                      Description Default          
The name of the input file. Can be specified using ${Property}. None - must be specified.
The literal string to search for in the input file. Can be specified using ${Property}. None - must be specified.
The literal string to use for the replacement string in the output file. Can be specified using ${Property}.
Use the syntax \$\{Property} to insert property notation in the output file.
None - must be specified.
The name of the output file. Can be specified using ${Property}. None - must be specified.
IfInputNotFound Indicate an action if the source file is not found: Ignore (ignore the missing file and do not warn), Warn (generate a warning message), Fail (generate a failure message) Warn


See the automated tests.


See Also