Insert
Strings
type file.txt | find /v "Some Text" > temp.txt && echo New Text >> temp.txt && type temp.txt > file.txt$content = Get-Content file.txt; $newContent = $content -replace "Pattern", "New Text$0"; $newContent | Set-Content file.txt$content = Get-Content -Path file.txt
$index = $content | Select-String -Pattern "specific pattern" -SimpleMatch | Select-Object -First 1 -ExpandProperty LineNumber
$before = $content[0..($index-2)] # Lines before the pattern
$after = $content[($index-1)..($content.Length-1)] # Lines including and after the pattern
$newContent = $before + "Your new text here" + $after
$newContent | Set-Content -Path file.txt(Get-Content file.txt) -replace 'Pattern', 'New Text' | Set-Content file.txtLines
Last updated