I need help with this script. I have slowly gotten this far, but need help at this point.
I need a script that will move text from the end of a section to to a certain point in the file, and then delete the moved text. The text that is to be moved has markers and so does the location. I need to be able to delete the text after the move. Also need to be done on multiple txt files in the same directory.
For example:
Sample Input .txt
A;1;1;####; (#### is the location (1) marker)
B
B
B
====-1234 (==== is the find (1) marker)
A;1;1;####; (#### is the location (2) marker)
B
B
B
====-5678 (==== is the find (2) marker)
After processing
A;1;1;1234;
B
B
B
A;1;1;5678;
B
B
B
The text file can have multiple groupings like this. Need to do this for each grouping from top to bottom. Here is what I have so far, it just moves the text and doesn't delete.
$file = "C:\Users\NX07934\Documents\Projects\23045\Docs\SampleData\*.txt"
$old = "\####"
$find = Get-ChildItem $file -recurse| Select-String -pattern "====-*"
$split = $find.ToString().Split("-")
$new = $split[1]
get-childitem "C:\Dir" -recurse -include *.txt |
select -expand fullname |
foreach
{
(Get-Content $_) -replace $old,$new |
Set-Content $_
}
Thanks for any and all help!