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 ..
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 ..
Assuming the robocopy log file is called robocopy.log
That would output all lines in the log file with the case insensitive string of TEST OK.Code:findstr /i /c:"TEST OK" robocopy.log
You can pipe that command to another file if needs be.
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
robk (27th July 2009)
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 ...
![]()
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?
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?
Sounds like grep then:
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:grep "Text OK" c:\foldername\*.* > c:\temp\results.txt
[code]
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 nextCode:grep "Text OK" c:\foldername\*.* | cut -d : 1-2 c:\temp\results.txt
grep and cut are standard on Unix/Linux but are freely available for Windows - Browse UnxUtils Files on SourceForge.net
There are currently 1 users browsing this thread. (0 members and 1 guests)