I need to replace the dollar amount in the last line of a file with $a (c:\myFile.txt)
$a = 1000 replace substring(3,4) replace 0500 with 1000
file looks like:
gadfg
agdaga
0000500
I need to replace the dollar amount in the last line of a file with $a (c:\myFile.txt)
$a = 1000 replace substring(3,4) replace 0500 with 1000
file looks like:
gadfg
agdaga
0000500
Please share your code, and the issue/question you have about it.
I think you will need to read the file, make the replacement, then write the file out. Look for a few threads earlier this month on this forum for code examples/solutions.
if 0500 only occurs once in the text file you could try
(get-content c:\test\replace.txt) | foreach-object {$_ -replace “0500”, “1000”} | set-content c:\test\replace.txt
maybe something like this:
$file = @"
gadfg
agdaga
0000500
"@
$file | out-file c:\temp\tempfile.txt
$content = get-content c:\temp\tempfile.txt
$newcontent = $content | select -SkipLast 1
$newcontent += ($content | select -Last 1) -replace ("0500","1000")