Help with a txt midifying script

Discussion in 'OT Technology' started by grooves12, Mar 3, 2007.

  1. grooves12

    grooves12 New Member

    Joined:
    Oct 3, 2003
    Messages:
    5,561
    Likes Received:
    0
    Location:
    Bay Area, CA
    Can anyone help me with a simple script??

    I have a huge csv that looks like this:
    Basically I want to remove everything except all of URLS that occur in the <A href="url"> sections
    Can anyone help out?
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,443
    Likes Received:
    12
    Code:
    [[email protected] ~]$ cat txt
    Watches and Jewels,6298,"<!-- Begin clixGalore Code--><img src=""http://www.is1.clixgalore.com/Impression.asp?BID=48123&AfID=95567&AdID=6298"" width=""0"" height=""0"" border=""0""><A href=""http://www.clixGalore.com/PSale.aspx?BID=48123&AfID=95567&AdID=6298&LP=www.w atchesandjewels.com"">Affiliates, Place Your Own Advertising Text Here. (ie) Click Here To Enter Merchant Website And View Products.</A><!-- End clixGalore Code-->"
    EZ Ticket - Sports Tickets | Concert Tickets | Theater Tickets | Tour Schedules & Information,6300,"<!-- Begin clixGalore Code--><img src=""http://www.is1.clixgalore.com/Impression.asp?BID=48135&AfID=95567&AdID=6300"" width=""0"" height=""0"" border=""0""><A href=""http://www.clixGalore.com/PSale.aspx?BID=48135&AfID=95567&AdID=6300&LP=www.e z-ticket.com"">Affiliates, Place Your Own Advertising Text Here. (ie) Click Here To Enter Merchant Website And View Products.</A><!-- End clixGalore Code-->"
    The Gold Sector Trading Advisory,6321,"<!-- Begin clixGalore Code--><img src=""http://www.is1.clixgalore.com/Impression.asp?BID=48321&AfID=95567&AdID=6321"" width=""0"" height=""0"" border=""0""><A href=""http://www.clixGalore.com/PSale.aspx?BID=48321&AfID=95567&AdID=6321&LP=www.t hegoldsector.com"">Trade Gold & Energy ETF's with 87% Accuracy!</A><!-- End clixGalore Code-->"
    535 Leathers,7195,"<!-- Begin clixGalore Code--><img src=""http://www.is1.clixgalore.com/Impression.asp?BID=58618&AfID=95567&AdID=7195"" width=""0"" height=""0"" border=""0""><A href=""http://www.clixGalore.com/PSale.aspx?BID=58618&AfID=95567&AdID=7195&LP=www.f ivethirtyfive.com"">Affiliates, Place Your Own Advertising Text Here. (ie) Click Here To Enter Merchant Website And View Products.</A><!-- End clixGalore Code-->"
    
    [[email protected] ~]$ cat txt | awk -F "A href=\"\"" '{print $2}' | awk -F \" '{print $1}'
    [URL="http://www.clixGalore.com/PSale.aspx?BID=48123&AfID=95567&AdID=6298&LP=www.w"]http://www.clixGalore.com/PSale.aspx?BID=48123&AfID=95567&AdID=6298&LP=www.w[/URL] atchesandjewels.com
    [URL="http://www.clixGalore.com/PSale.aspx?BID=48135&AfID=95567&AdID=6300&LP=www.e"]http://www.clixGalore.com/PSale.aspx?BID=48135&AfID=95567&AdID=6300&LP=www.e[/URL] z-ticket.com
    [URL="http://www.clixGalore.com/PSale.aspx?BID=48321&AfID=95567&AdID=6321&LP=www.t"]http://www.clixGalore.com/PSale.aspx?BID=48321&AfID=95567&AdID=6321&LP=www.t[/URL] hegoldsector.com
    [URL="http://www.clixGalore.com/PSale.aspx?BID=58618&AfID=95567&AdID=7195&LP=www.f"]http://www.clixGalore.com/PSale.aspx?BID=58618&AfID=95567&AdID=7195&LP=www.f[/URL] ivethirtyfive.com
    
    To remove that space in the url I just

    Code:
    [[email protected] ~]$ cat txt | awk -F "A href=\"\"" '{print $2}' | awk -F \" '{print $1}' | sed s/" "//g
    http://www.clixGalore.com/PSale.aspx?BID=48123&AfID=95567&AdID=6298&LP=www.watchesandjewels.com
    http://www.clixGalore.com/PSale.aspx?BID=48135&AfID=95567&AdID=6300&LP=www.ez-ticket.com
    http://www.clixGalore.com/PSale.aspx?BID=48321&AfID=95567&AdID=6321&LP=www.thegoldsector.com
    http://www.clixGalore.com/PSale.aspx?BID=58618&AfID=95567&AdID=7195&LP=www.fivethirtyfive.com
    [[email protected] ~]$
    
     
    Last edited: Mar 4, 2007
  3. grooves12

    grooves12 New Member

    Joined:
    Oct 3, 2003
    Messages:
    5,561
    Likes Received:
    0
    Location:
    Bay Area, CA
    Thanks,

    A) Is it possible to do this in windows?
    B) Is it possible to make it a 1-step process through some sort of batch file so I can do a "command.bat text.txt" and get an output file?
     
  4. peerk

    peerk New Member

    Joined:
    Mar 14, 2005
    Messages:
    984
    Likes Received:
    0
    I think this will work.

    Copy and paste this code into notepad and give the file a ".vbs" extension.

    Code:
    Option Explicit
    
    Dim strText, fso, inFile, outFile, startPos, stopPos, url, length
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set inFile = fso.OpenTextFile("in.txt", 1)
    Set outFile = fso.OpenTextFile("out.txt", 2)
    
    strText = inFile.ReadAll
    inFile.Close
    
    stopPos = 1
    startPos = 1
    
    Do While startPos > 0
    	startPos = inStr(stopPos, strText, "<A href=""""")
    	
    	if startPos > 0 then
    		stopPos = inStr(startPos + 10, strText,">")
    		length = (stopPos - 2) - (startPos + 10)
    		url = Mid(strText, startPos+10, length)
    		
    		outFile.writeLine url
    	end if
    
    Loop
    
    outFile.close
    
    Put your data in a file called "in.txt". Place the script and "in.txt" in the same folder. After you run the script the output should be in "out.txt".
     

Share This Page