# Thread: Script to move text around...

1. Registered User
Join Date
Aug 2009
Posts
23
Rep Power
0

## Script to move text around...

Hopefully I am posting this in the right place...

I have some text, of about 700 lines like this:

And I want to change it all to this:

My Googling says maybe a batch script, but I don't know how to go about writing that. So any help would be greatly appreciated!

2. 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
Set objFso = CreateObject("Scripting.FileSystemObject")

' 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

' Write a corrected line to the new file
Loop

' Cleanup
objInFile.Close
objOutFile.Close

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
End Function
Last edited by Nilpo; January 10th, 2013 at 03:26 PM.

3. Registered User
Join Date
Aug 2009
Posts
23
Rep Power
0
Thanks! Will give it a go! (Sorry for the slow reply!)

4. Registered User
Join Date
Aug 2009
Posts
23
Rep Power
0
Couldn't get it to work

Should I be running it from cmd with the correct directory and cscript script.vbs? Thanks!