Advertisement
Guest User

Powershell Text Replacement Script

a guest
Feb 13th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Replace-Number($input_file, $output_file) {
  2.     $start = Read-Host "Enter starting number: "
  3.     $line_number = [int]$start
  4.  
  5.     Get-Content $input_file | ForEach-Object {
  6.         $new_line = $_.Substring(0, 19) + $line_number.ToString("D4") + $_.Substring(23)
  7.         $new_line | Out-File $output_file -Append
  8.         $line_number++
  9.     }
  10. }
  11.  
  12. # Example usage
  13. Replace-Number 'input.txt' 'output.txt'
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement