This script will work. Save it with a .vbs extension and make sure the variables point to real files.
Code:
' Set paths to the files
strInFile = "C:\path\to\original\file.txt"
strOutFile = "C:\path\to\output\file.txt"
' Open the file for reading
Const ForReading = 1
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFso.OpenTextFile(strInFile, ForReading)
' Create an output file
Set objOutFile = objFso.CreateTextFile(strOutFile)
' Read in the file contents one line at a time
Do While Not objInFile.AtEndOfStream
' Get a line of text from the original file
strText = objInFile.ReadLine
' Write a corrected line to the new file
objOutFile.WriteLine FixLink(strText)
Loop
' Cleanup
objInFile.Close
objOutFile.Close
Function FixLink(strInput)
If strInput <> "" Then
' Use a regular expression to identify all of the pieces
With New RegExp
.IgnoreCase = vbTrue
.Global = vbTrue
.Pattern = "^(<.*?>)(#\d+)(</a>) (.*)$"
Set colMatches = .Execute(strInput)
End With
Set colParts = colMatches(0).SubMatches
' Put the pieces back in the right order
strOutput = colParts(1) & " " & colParts(0) & colParts(3) & colParts(2)
Else
strOutput = ""
End If
' Send the corrected link back to the main script
FixLink = strOutput
End Function