1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2009
    Rep Power

    Script to move text around...

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

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

    <a href="https://twitter.com/twitterhandle/status/534642248095">#301</a> Beastie Boys - Netty's Girl
    <a href="https://twitter.com/twitterhandle/status/222113034104">#300</a> TLC - No Scrubs
    <a href="https://twitter.com/twitterhandle/status/893745637382">#299</a> Oasis - Supersonic
    <a href="https://twitter.com/twitterhandle/status/747456265217">#298</a> Elvis Costello - Human Touch

    And I want to change it all to this:

    #301 <a href="https://twitter.com/twitterhandle/status/534642248095">Beastie Boys - Netty's Girl</a>
    #300 <a href="https://twitter.com/twitterhandle/status/222113034104">TLC - No Scrubs</a>
    #299 <a href="https://twitter.com/twitterhandle/status/893745637382">Oasis - Supersonic</a>
    #298 <a href="https://twitter.com/twitterhandle/status/747456265217">Elvis Costello - Human Touch</a>

    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. #2
  3. ASP Hero (2000 - 2499 posts)

    Join Date
    Jun 2006
    New Springfield, OH
    Rep Power
    This script will work. Save it with a .vbs extension and make sure the variables point to real files.

    ' 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)
    ' Cleanup
    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)
    		strOutput = ""
    	End If
    	' Send the corrected link back to the main script
    	FixLink = strOutput
    End Function
    Last edited by Nilpo; January 10th, 2013 at 04:26 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!!
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2009
    Rep Power
    Thanks! Will give it a go! (Sorry for the slow reply!)
  6. #4
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2009
    Rep Power
    Couldn't get it to work

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

Similar Threads

  1. Replies: 0
    Last Post: August 8th, 2012, 06:12 PM
  2. Script to read a CSV and move files based on paths
    By drl213 in forum Windows Scripting
    Replies: 0
    Last Post: April 28th, 2011, 01:06 PM
  3. Need script to move (video)files once they have been watched
    By JohnLisle in forum Windows Scripting
    Replies: 1
    Last Post: September 25th, 2010, 12:54 AM
  4. Is This Possible to Color a text using VB SCRIPT
    By MRRaja in forum ASP Development
    Replies: 4
    Last Post: August 24th, 2010, 08:03 AM
  5. move text from text box to a table (add a record).
    By tbeersma in forum Microsoft Access Help
    Replies: 3
    Last Post: May 27th, 2004, 10:56 AM

IMN logo majestic logo threadwatch logo seochat tools logo