AssignMod

Top  Previous  Next

 

The AssignMod command allows you to define additional search and replace assignments in addition to any that are already defined by the Mod command, or to replace ones that have been removed using the ClearMod command, and to do this at runtime rather than when the script is initially processed. The Mod assignments can then be executed using the ModifyFile command within the script. AssignMod commands are only applicable to the User Section in which they are defined.

lamp Important: This command should not be used to define initial Mod assignments. The purpose of this command is to allow Mod assignments to be made after other operations defined within the same user section. For example, you may wish to perform a set of substitutions or insertions on a document, then clear the Mod assignments and define some new ones without creating a new section. Note that the AssignMod command only defines the substitution or insertion 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 changes.

A common use for this is to automatically update an external document or 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.

 

Command Syntax

 

AssignMod:[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.

/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.

 

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

 

[My Section]

; Clear any existing Mod assignments

ClearMod:

; Add a new assignment

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

; Perform the substitution

ModifyFile:"C:\Test Text.txt","C:\Test Text (updated).txt"        

 

See Also: ClearMod Mod ModifyFile RegexReplace Variables