Mod

Top  Previous  Next

 

The Mod command allows you to define search and replace text that can then be executed using the ModifyFile command within the script. Mod commands have local scope, so are only applicable to the User Section in which they are defined.

 

A common use for this is to automatically update an external script for another application that can itself be run from the current PipelineRunner script. For example, before creating installers you might want to update the installer scripts with version information defined in the Setup section of the current script or retrieved from the compiled executable using Special Functions such as GetFileVersion.

lamp Important: This command only defines the substitution and assigns it to the Mods list in the current section. A subsequent ModifyFile command within the same section is required to perform the actual modification.

Command Syntax

 

Mod:[TextToLocate],[ReplacementText],[CommandSwitches]

 

The colon after the command, and comma between parameters are compulsory. Command switches are optional. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, nor are the command line switches, but parameters may be case sensitive depending on whether or not the IgnoreCase flag has been set.

 

Parameters:

 

TextToLocate: The text that you wish to locate within the text file specified by the ModifyFile command. The text must be surrounded by quotation marks.

ReplacementText: The value to be assigned to the text located in the target file, or if you plan to use the /FromFile command switch a fully qualified path and file name which contains the value to be assigned.  The text must be surrounded by quotation marks regardless of content.

 

All parameters are compulsory. If any parameter is missing or invalid an error will be thrown.

 

Command Switches

 

There are six optional command line switches which can be used to determine how the the search and replace operation is handled:

 

/FromFile: If this switch is set and the content of the ReplacementText parameter is a fully qualified path and file name to a text file, the content of that file will be used as the replacement text. If it is not set, the search will be case sensitive. In either case the replacement text will be inserted verbatim.

/IgnoreCase: If this switch is set the search will not be case sensitive. If it is not set, the search will be case sensitive. In either case the replacement text will be inserted verbatim.

/InsertAfter: If this switch is set the ReplacementText will be inserted immediately after the located text rather than replacing the existing text or line.

/InsertBefore: If this switch is set the ReplacementText will be inserted immediately before the located text rather than replacing the existing text or line.

/LineStartsWith: If this switch is set the ModifyFile command will only replace instances where the line starts with the specified text. If this switch is not set all instances will be replaced regardless of where they are located.

/NewLineAfter: the NewLine character or character set for the current operating system will be added after the new text.

/NewLineBefore: the NewLine character or character set for the current operating system will be added before the new text.

/NewLineBeforeIfNotPresent: the NewLine character or character set for the current operating system will be added before the new text .

/NewLineBeforeAndAfter: the NewLine character or character set for the current operating system will be added before and after the new text.a blank line will be added before  the remark text.

/NewLineBeforeIfNotPresentAndAfter: the NewLine character or character set for the current operating system will be added before the new text if a Newline character does not already exist, and a further NewLine will be added after the text.

/ReplaceWholeLine: If this switch is set the entire line will be replaced.  This is typically used with the /LineStartsWith switch to locate a particular part of a command and replace the entire line with a new value. Otherwise the original text will be replaced the the replacement text and any other text in the line will be left unchanged.

lamp Important: Only one of the NewLine command line switches can be used. If you define more than one NewLine command line switch, the last one encountered when parsing the script will be used and the others ignored.

Example:

 

The following command will assign a substitution definition that will search for any lines starting with AppVerName= and replace the entire line with AppVerName=MyApp plus the value of the Version variable, ignoring character case in the search

 

Mod:”AppVerName=”,”AppVerName=MyApp %%Version%%”,/LineStartsWith /ReplaceWholeLine /IgnoreCase

 

See Also: AssignMod ModifyFile RegexReplace Variables Special Functions GetFileVersion