+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Robocopy some help... in Coding and Web Development; Hi all I would know how to extract robocopy one line or more lines in a file .txt or to ...
  1. #1

    Join Date
    Jul 2009
    Location
    Romania
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Exclamation Robocopy some help...

    Hi all I would know how to extract robocopy one line or more lines in a file .txt or to look after certain characters such as TEST OK or something. Thanks in advance ..

  2. #2
    TheLibrarian
    Guest
    Assuming the robocopy log file is called robocopy.log

    Code:
    findstr /i /c:"TEST OK" robocopy.log
    That would output all lines in the log file with the case insensitive string of TEST OK.

    You can pipe that command to another file if needs be.

  3. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Not sure what you're doing, but I used to use robocopy to backup servers and the following subroutine was used to scan the logs (which could be massive!) to find the error line. It's called with the name of the log file to check; oFSO is the filesystemobject and it's writing a block of HTML in a variable called sSummary. This is then written to a web page that can be quickly checked to see if there are errors.

    It starts by scanning backwards looking for the normal ending block (it has a row of dashes then the stats; this should happen less than 20 lines from the end of the file). If it doesn't find this then it knows that the backup failed to complete.

    If robocopy completed, the script then keeps scanning the log looking for "ERROR: RETRY LIMIT EXCEEDED" - if it finds this then it writes the previous lines to the sSummary variable.

    grep and findstr work well and they're quick; the downside is that they don't give you context (so you may know an error occurred but you don't know what it was). This was designed so that IT Support staff could quickly glance at a web page and see if there were any errors and what they were.

    Code:
      sub ScanFile(sFile)
      	iLine = 0
      	set oScanFile = oFSO.OpenTextFile(sfile, 1)
        sText=oScanFile.readall
        aFileLines=split(sText,vbcrlf)
      	oScanFile.Close
      	iLine = Ubound(aFileLines)
      	sSummary=""
      	do while left(aFileLines(iLine),10)<>string(10,"-") and iFooter<20
      	 sSummary=aFileLines(iLine) & vbcrlf & sSummary
      	 iLine=iLine-1
      	 iFooter=iFooter+1
      	loop
      	if iFooter>=20 then
          iSlash=instrrev(sFile,"\")
          sJob=mid(sFile,iSlash+1,len(sFile)-iSlash-10)
          sSummary="<h2>Backup not completed</h2>"
          sSummary=sSummary & "<p>To re-run this backup, type <pre>\\student\adminscripts\back.wsf /job:" & sJob & "</pre>"
          sSummary=sSummary & " at a prompt on computer " & sBackupServer & "</p>"
          iLine=Ubound(afileLines)
      	else
      	 	sSummary="<pre>" & sSummary & "</pre>"
      	end if
        ofile.writeline "<pre>"
      	For l=iLine to LBound(aFileLines) Step -1
        	if instr(aFileLines(l),"ERROR: RETRY LIMIT EXCEEDED.")>0 then
        	   oFile.writeLine aFileLines(l-3)
        	   oFile.writeLine aFileLines(l-2)
      '  	   oFile.writeLine aFileLines(l-1)
        	   oFile.writeLine aFileLines(l)
        	   l=l-4
        	end if
        	if instr(aFileLines(l)," ERROR ")<>0 then
          '  if isdate(left(aFileLines(l),8)) then
        	   oFile.writeLine aFileLines(l)
             oFile.writeLine aFileLines(l+1)
    
        '    end if
          end if
      	Next
      	oFile.write "</pre>" & sSummary
      end sub

  4. Thanks to srochford from:

    robk (27th July 2009)

  5. #4

    Join Date
    Jul 2009
    Location
    Romania
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    is not working .. this 2 post offff
    i wanna extract one line or more lines in a file .txt and put in the another .txt file whit a robocopy.... EX:

    in the a.txt is a line like "Text OK - is done", but not only ... there are several lines

    and i wanna copy this line "Text OK - is done" and put in the b.txt file. in the another location...

    sorry for my bad english .. i`m romanian guy ... THANKS in advence .. i`m w8ing replay ...

  6. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Not sure I understand. What has robocopy got to do with this? Are you just copying files with robocopy but you also want to check the contents of the file?

    What I posted before was assuming you were running robocopy and getting a log fille - you then wanted to get something out of the log.

    Could you try and describe a bit more what you're trying to do?

  7. #6
    leco's Avatar
    Join Date
    Nov 2006
    Location
    West Yorkshire
    Posts
    2,026
    Thank Post
    595
    Thanked 125 Times in 119 Posts
    Rep Power
    41
    From my understanding of the op's request - he has a number of files (type unknown) that he wants to test for, extract and write to another file, a specific set of characters.

    e.g. File A contains: Blah blah blah Test OK blah blah blah.
    Procedure would extract "Test OK" and write it to File B

    Although like you I am unsure of the exact purpose of such a project.

    Again from my understanding of what Robocopy does, I don't think that this is the correct tool. It surely should be more of a search tool/script that would carry out such a procedure?

  8. #7

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Sounds like grep then:

    Code:
    grep "Text OK" c:\foldername\*.* > c:\temp\results.txt
    will search all files in c:\foldername and, if they contain "Text OK" will write their name to c:\temp\results.txt (it will do a bit more than that - you'll get the name of the file and the line containing the text. If you just want the file name you can use cut:
    [code]
    Code:
    grep "Text OK" c:\foldername\*.* | cut -d : 1-2 c:\temp\results.txt
    cut is saying that the text input to it is delimited with : and you want to keep fields 1 and 2 (so if you have a line like C:\folder1\folder2\file.txt:Text OK then you get c:\folder1\folder2\file.txt - field 1 is the "c"; field 2 is everything else up to the next

    grep and cut are standard on Unix/Linux but are freely available for Windows - Browse UnxUtils Files on SourceForge.net

SHARE:
+ Post New Thread

Similar Threads

  1. Robocopy help needed
    By Jobos in forum Windows
    Replies: 1
    Last Post: 19th November 2008, 04:19 PM
  2. Robocopy where is it and how do I use it?
    By speckytecky in forum Windows
    Replies: 10
    Last Post: 29th July 2008, 09:29 AM
  3. Robocopy Help
    By Gatt in forum Windows
    Replies: 2
    Last Post: 11th July 2008, 11:06 AM
  4. Robocopy Help
    By soze in forum How do you do....it?
    Replies: 15
    Last Post: 2nd June 2008, 02:42 PM
  5. Robocopy
    By acrobson in forum How do you do....it?
    Replies: 16
    Last Post: 22nd December 2007, 01:41 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •