en-US/PowerShell.MCP.dll-Help.xml
|
<?xml version="1.0" encoding="utf-8"?>
<helpItems xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" schema="maml" xmlns="http://msh"> <command:command> <command:details> <command:name>Add-LinesToFile</command:name> <maml:description> <maml:para>Insert lines into a text file at a specific position or at the end</maml:para> </maml:description> <command:verb>Add</command:verb> <command:noun>LinesToFile</command:noun> </command:details> <maml:description> <maml:para>Inserts lines at specified position or appends to end. Creates new file if not exists.</maml:para> <maml:para>Add-LinesToFile file.txt -Content "new line" # append to end</maml:para> <maml:para>Add-LinesToFile file.txt -LineNumber 5 -Content "inserted" # insert at line 5</maml:para> <maml:para>Add-LinesToFile file.txt -Content @("line1", "line2") # add multiple lines</maml:para> <maml:para>Add-LinesToFile new.txt -Content "first line" # create new file</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Add-LinesToFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="none"> <maml:name>Content</maml:name> <maml:description> <maml:para>Lines to insert. String or array of strings.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineNumber</maml:name> <maml:description> <maml:para>Insert position (1-based). Omit to append at end.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Int32</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Add-LinesToFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="none"> <maml:name>Content</maml:name> <maml:description> <maml:para>Lines to insert. String or array of strings.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineNumber</maml:name> <maml:description> <maml:para>Insert position (1-based). Omit to append at end.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Int32</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="none"> <maml:name>Content</maml:name> <maml:description> <maml:para>Lines to insert. String or array of strings.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineNumber</maml:name> <maml:description> <maml:para>Insert position (1-based). Omit to append at end.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Int32</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <dev:name>System.String</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> <command:inputType> <dev:type> <dev:name>System.Object</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <maml:alertSet> <maml:alert> <maml:para>- Creates the file if it does not exist (no flag needed). Exception: wildcards in `-Path` cannot create new files. - Omitting `-LineNumber` appends to end; `-LineNumber 1` inserts at beginning (existing lines shift down). - To pass content containing `$`, backticks, or quotes, use the `var1` parameter of `invoke_expression`: `Add-LinesToFile path -Content $var1`</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>--------- Basic usage ---------</maml:title> <maml:introduction> <maml:para>Add-LinesToFile file.txt -Content "new line" Add-LinesToFile file.txt -LineNumber 1 -Content "first" Add-LinesToFile file.txt -Content @("line1", "line2")</maml:para> </maml:introduction> <dev:code /> <dev:remarks /> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-LinesInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-MatchInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-LinesFromFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Show-TextFiles</maml:linkText> <command:uri /> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command> <command:details> <command:name>Remove-LinesFromFile</command:name> <maml:description> <maml:para>Remove lines from a text file by line range or pattern matching</maml:para> </maml:description> <command:verb>Remove</command:verb> <command:noun>LinesFromFile</command:noun> </command:details> <maml:description> <maml:para>Removes lines by range, literal match, or regex. Range + pattern = AND condition.</maml:para> <maml:para>Remove-LinesFromFile file.txt -LineRange 5,10 # remove lines 5-10</maml:para> <maml:para>Remove-LinesFromFile file.txt -LineRange -10 # remove last 10 lines</maml:para> <maml:para>Remove-LinesFromFile file.txt -Pattern "^#" # remove all comment lines</maml:para> <maml:para>Remove-LinesFromFile file.txt -Contains "DEBUG" # remove lines containing "DEBUG"</maml:para> <maml:para>Remove-LinesFromFile file.txt -Contains "DEBUG" -Pattern "^#" # OR condition (either match)</maml:para> <maml:para>Remove-LinesFromFile file.txt -Contains "line1`nline2" # multiline removal (whole-file mode)</maml:para> <maml:para>Remove-LinesFromFile file.txt -LineRange 1,100 -Pattern "TODO" # AND condition</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Remove-LinesFromFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string to match lines for removal. Can be combined with `-Pattern` (OR condition). Supports multiline strings (newlines allowed) for whole-file removal mode. Cannot be combined with `-Pattern` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to remove. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to match lines for removal.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Remove-LinesFromFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string to match lines for removal. Can be combined with `-Pattern` (OR condition). Supports multiline strings (newlines allowed) for whole-file removal mode. Cannot be combined with `-Pattern` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to remove. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to match lines for removal.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string to match lines for removal. Can be combined with `-Pattern` (OR condition). Supports multiline strings (newlines allowed) for whole-file removal mode. Cannot be combined with `-Pattern` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to remove. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to match lines for removal.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <dev:name>System.String</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <maml:alertSet> <maml:alert> <maml:para>- At least one of `-LineRange`, `-Contains`, or `-Pattern` required. - `-Contains` and `-Pattern` can be combined (OR condition). - `-Contains` supports multiline strings for whole-file removal mode (like `Update-MatchInFile -OldText`). - Multiline `-Contains` cannot be combined with `-Pattern` or tail `-LineRange`. - `-LineRange` + `-Pattern`/`-Contains` = AND condition. - To pass literal text containing `$`, backticks, or quotes to `-Contains`, use the `var1` parameter of `invoke_expression`: `Remove-LinesFromFile path -Contains $var1`</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>--------- Basic usage ---------</maml:title> <maml:introduction> <maml:para>Remove-LinesFromFile file.txt -LineRange 5,10 Remove-LinesFromFile file.txt -Pattern "^#" Remove-LinesFromFile file.txt -Contains "DEBUG"</maml:para> </maml:introduction> <dev:code /> <dev:remarks /> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-LinesToFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-LinesInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-MatchInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Show-TextFiles</maml:linkText> <command:uri /> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command> <command:details> <command:name>Show-TextFiles</command:name> <maml:description> <maml:para>Display file contents with line numbers, or search across files with regex or literal patterns</maml:para> </maml:description> <command:verb>Show</command:verb> <command:noun>TextFiles</command:noun> </command:details> <maml:description> <maml:para>Display file contents with line numbers, or search across files using regex/literal patterns with highlighted matches and context lines.</maml:para> <maml:para>Show-TextFiles file.txt # entire file</maml:para> <maml:para>Show-TextFiles file.txt -LineRange 10,20 # lines 10-20 Show-TextFiles file.txt -LineRange 10-20 # same (dash format)</maml:para> <maml:para>Show-TextFiles file.txt -LineRange -10 # last 10 lines</maml:para> <maml:para>Show-TextFiles file.txt -Pattern "error" # regex search with context</maml:para> <maml:para>Show-TextFiles file.txt -Contains "[Error]" # literal search (no escaping needed)</maml:para> <maml:para>Show-TextFiles file.txt -Contains "line1`nline2" # multiline literal search (whole-file mode)</maml:para> <maml:para>Show-TextFiles app.?? -Recurse -Pattern "TODO" # recursive wildcard search</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Show-TextFiles</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string search. No regex escaping needed. Supports multiline strings (newlines allowed) for whole-file search mode. Cannot be combined with `-Pattern` when multiline. Cannot be used with `-Recurse` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards. With `-Recurse`, wildcard patterns filter files by extension across all subdirectories.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern. Matches shown with context.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Recurse</maml:name> <maml:description> <maml:para>Search subdirectories. Requires -Pattern or -Contains.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Show-TextFiles</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string search. No regex escaping needed. Supports multiline strings (newlines allowed) for whole-file search mode. Cannot be combined with `-Pattern` when multiline. Cannot be used with `-Recurse` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern. Matches shown with context.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Recurse</maml:name> <maml:description> <maml:para>Search subdirectories. Requires -Pattern or -Contains.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Contains</maml:name> <maml:description> <maml:para>Literal string search. No regex escaping needed. Supports multiline strings (newlines allowed) for whole-file search mode. Cannot be combined with `-Pattern` when multiline. Cannot be used with `-Recurse` when multiline.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format). Negative value = tail count (e.g., `-10` = last 10 lines).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards. With `-Recurse`, wildcard patterns filter files by extension across all subdirectories.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern. Matches shown with context.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Recurse</maml:name> <maml:description> <maml:para>Search subdirectories. Requires -Pattern or -Contains.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <dev:name>System.String</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <maml:alertSet> <maml:alert> <maml:para>- `-LineRange -10` = last 10 lines (single negative value = tail) - `-Contains` and `-Pattern` can be combined (OR condition) - `-Contains` supports multiline strings for whole-file search mode (like `Update-MatchInFile -OldText`) - Multiline `-Contains` cannot be combined with `-Pattern` or `-Recurse` - `-Recurse` requires `-Pattern` or `-Contains` - `-Recurse` with wildcard `-Path` (e.g., `*.cs`) filters files by extension - `-LiteralPath` for paths with `[`, `]`, `*`, `?`</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>--------- Basic usage ---------</maml:title> <maml:introduction> <maml:para>Show-TextFiles file.txt Show-TextFiles file.txt -LineRange 10,20 Show-TextFiles file.txt -Pattern "error" Show-TextFiles *.cs -Recurse -Pattern "class\s+\w+" Show-TextFiles *.log -Recurse -Contains "[FATAL]"</maml:para> </maml:introduction> <dev:code /> <dev:remarks /> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-LinesToFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-LinesInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-MatchInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-LinesFromFile</maml:linkText> <command:uri /> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command> <command:details> <command:name>Update-LinesInFile</command:name> <maml:description> <maml:para>Replace or delete specific lines in a text file</maml:para> </maml:description> <command:verb>Update</command:verb> <command:noun>LinesInFile</command:noun> </command:details> <maml:description> <maml:para>Replaces specified line range with new content. Lines can expand or shrink.</maml:para> <maml:para>Update-LinesInFile file.txt -LineRange 5 -Content "replaced" # replace line 5</maml:para> <maml:para>Update-LinesInFile file.txt -LineRange 5,10 -Content "single line" # replace 6 lines with 1</maml:para> <maml:para>Update-LinesInFile file.txt -LineRange 5,10 -Content @() # delete lines 5-10</maml:para> <maml:para>Update-LinesInFile file.txt -Content @("line1", "line2") # replace entire file</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Update-LinesInFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to replace. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Omit to replace entire file.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Update-LinesInFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to replace. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Omit to replace entire file.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Line range to replace. Accepts: `5` (single line), `5,10` (range), `5-10` (dash format). Omit to replace entire file.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <dev:name>System.String</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> <command:inputType> <dev:type> <dev:name>System.Object</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <maml:alertSet> <maml:alert> <maml:para>- `-Content @()` deletes lines (empty array). - Omitting `-LineRange` replaces entire file. - To pass content containing `$`, backticks, or quotes, use the `var1` parameter of `invoke_expression`: `Update-LinesInFile path -LineRange 5 -Content $var1`</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>--------- Basic usage ---------</maml:title> <maml:introduction> <maml:para>Update-LinesInFile file.txt -LineRange 5 -Content "replaced" Update-LinesInFile file.txt -LineRange 5,10 -Content @() Update-LinesInFile file.txt -Content @("new content")</maml:para> </maml:introduction> <dev:code /> <dev:remarks /> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-LinesToFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-MatchInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-LinesFromFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Show-TextFiles</maml:linkText> <command:uri /> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command> <command:details> <command:name>Update-MatchInFile</command:name> <maml:description> <maml:para>Replace text in a file using literal string or regex pattern</maml:para> </maml:description> <command:verb>Update</command:verb> <command:noun>MatchInFile</command:noun> </command:details> <maml:description> <maml:para>Replaces matching text (literal or regex) within optional line range. OldText supports multiline strings (whole-file replacement mode).</maml:para> <maml:para>Update-MatchInFile file.txt -OldText "foo" -Replacement "bar" # literal replacement</maml:para> <maml:para>Update-MatchInFile file.txt -Pattern "v\d+" -Replacement "v2" # regex replacement</maml:para> <maml:para>Update-MatchInFile file.txt -LineRange 10,20 -OldText "old" -Replacement "new" # within range</maml:para> <maml:para>Update-MatchInFile file.txt -LineRange 10 -OldText "old" -Replacement "new" # single line</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Update-MatchInFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Limits replacement to specific lines. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to find.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Update-MatchInFile</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Limits replacement to specific lines. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to find.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Backup</maml:name> <maml:description> <maml:para>Creates a backup file before modifying.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>Prompts you for confirmation before running the cmdlet.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Character encoding. Auto-detected if omitted.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>First</maml:name> <maml:description> <maml:para>Number of lines to process. Use with `-Skip` to define a range, or alone to process from the beginning. Mapped to `-LineRange` internally (e.g., `-First 20` becomes `-LineRange 1-20`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>LineRange</maml:name> <maml:description> <maml:para>Limits replacement to specific lines. Accepts: `5` (single line), `10,20` (range), `10-20` (dash format).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>File path(s). Supports wildcards.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">System.String[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>Regex pattern to find.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.String</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>Skip</maml:name> <maml:description> <maml:para>Number of lines to skip from the beginning. Use with `-First` to define a window (e.g., `-Skip 200 -First 50` becomes `-LineRange 201-250`). Use alone to skip lines and process to end of file (e.g., `-Skip 100` becomes `-LineRange 101,-1`).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Nullable`1[System.Int32]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="Named" aliases="none"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>Runs the command in a mode that only reports what would happen without performing the actions.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="true">System.Management.Automation.SwitchParameter</command:parameterValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <dev:name>System.String</dev:name> </dev:type> <maml:description> <maml:para>File path(s) to process.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues /> <maml:alertSet> <maml:alert> <maml:para>- `-OldText` (literal) and `-Pattern` (regex) are mutually exclusive. - `-OldText` supports multiline strings for whole-file replacement mode. - `-WhatIf` shows detailed preview with highlighting. - Newlines in `-Replacement` are normalized to match file's newline style. - To pass text containing `$`, backticks, or quotes, use `var1`/`var2` parameters of `invoke_expression`: `Update-MatchInFile path -OldText $var1 -Replacement $var2`</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>--------- Basic usage ---------</maml:title> <maml:introduction> <maml:para>Update-MatchInFile file.txt -OldText "foo" -Replacement "bar" Update-MatchInFile file.txt -Pattern "v\d+" -Replacement "v2" Update-MatchInFile file.txt -LineRange 10,20 -OldText "old" -Replacement "new"</maml:para> </maml:introduction> <dev:code /> <dev:remarks /> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-LinesToFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-LinesInFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-LinesFromFile</maml:linkText> <command:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Show-TextFiles</maml:linkText> <command:uri /> </maml:navigationLink> </command:relatedLinks> </command:command> </helpItems> |