kris06 Posted January 18, 2008 Share Posted January 18, 2008 Hi all, I have two files, (file1 and file2). file1 contains columns and rows of data which are actually filepaths for example ("\\vector\codereview\SIP\sipchannel.h"). several such filepath exists. file2 contains %sip% Roger Tony Tim File2's first row contains the keyword for example %sip% (anything with sip, need wildcard here). my objective is, the script should read file1 and file2 and for every occurance of "sip" in file1, it should return the names of the reviewers (Roger Tony Tim) along with the filename. I would really appreciate If somebody could help me acheive this. Thanks in advance. Rgds, Kris Link to comment Share on other sites More sharing options...
randallc Posted January 18, 2008 Share Posted January 18, 2008 Hi, I cuould try, but need you to post some truncated example files 1 and 2. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi,I cuould try, but need you to post some truncated example files 1 and 2.Best, RandallHi Randall, Heres an example of file1 : ------------------------------- //vecor/releases/4.5/SIP/MS/rtaudio.pjt //vector/releases/4.5/dsp/MS/rtaudio/audio/wmspeech/v10_16bPK/common/com_wmsauxcode_16.c Heres an example of file2: ------------------------------- %/sip/% Tony Terry Andy %/dsp_user/% Sam AndyThanks,kris Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 I forgot to add that, the result should be written to another file. like, filepath, filename, reviewername Link to comment Share on other sites More sharing options...
randallc Posted January 18, 2008 Share Posted January 18, 2008 Hi, so is is the same line in each file?; else how do you identify which reviewer to use? #include<file.au3> local $sFile1=@ScriptDir&"\file1.txt",$sFile2=@ScriptDir&"\file2.txt",$sFileResult=@ScriptDir&"\results.txt",$c=FileDelete($sFileResult) local $arFile1,$arFile2,$arResults[1],$c=_FileReadToArray($sFile1,$arFile1),$c=_FileReadToArray($sFile2,$arFile2),$k redim $arResults[UBound($arFile1)] for $i= 1 to UBound($arFile1)-1 if StringInStr($arFile1[$i],"sip") then $arResults[$k]=$arFile1[$i]&"|Reviewer: "&StringReplace($arFile2[$i],"%/sip/%","") $k+=1 next redim $arResults[$k-1] _FileWriteFromArray($sFileResult,$arResults) ; bug with blank first line fixed in 3.2.11.0 run("notepad "&$sFileResult)Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi, so is is the same line in each file?; else how do you identify which reviewer to use? #include<file.au3> local $sFile1=@ScriptDir&"\file1.txt",$sFile2=@ScriptDir&"\file2.txt",$sFileResult=@ScriptDir&"\results.txt",$c=FileDelete($sFileResult) local $arFile1,$arFile2,$arResults[1],$c=_FileReadToArray($sFile1,$arFile1),$c=_FileReadToArray($sFile2,$arFile2),$k redim $arResults[UBound($arFile1)] for $i= 1 to UBound($arFile1)-1 if StringInStr($arFile1[$i],"sip") then $arResults[$k]=$arFile1[$i]&"|Reviewer: "&StringReplace($arFile2[$i],"%/sip/%","") $k+=1 next redim $arResults[$k-1] _FileWriteFromArray($sFileResult,$arResults) ; bug with blank first line fixed in 3.2.11.0 run("notepad "&$sFileResult)Best, Randall Hi, Thanks for efforts. to answer the question, no the same line is not in each file. file2 actually contains the reviewer names. example: %/sip/% Tony Allen file1 contains the actual filename. example: "c:\release\review\sip\channel.h" "c:\release\review\ms\isdn\trunk.h" now, my script should parse through both file1 and file2 and create a results.txt file and write into it as c:\release\review\sip\channel.h Tony allen so basically "sip" is the search criteria(file2). and whenever an occurence of sip happens in file1. it should give me the filepath and reviewer name, written to another file. I am doing this to start implementing mandatory reviewers for each file. Randall, tried your code, and it doesnt write anythin to results.txt. Thanks a ton, Kris Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 i have attached sample file1 and file2. Hope this helps!! Thanks, Krisfile1.txtfile2.txt Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 i have attached sample file1 and file2. Hope this helps!!Thanks,KrisRandall, The code does work. my mistake. file2 didnt contain "sip" keyword , hence the script dint write anythin. however it still doesnt solve my problem. the same script needs to be changed so that, it doesnt look for one specific keyword in this case "sip", insteads gets them from file2. and outputs the results to another file(same as the way ur code does).this way, i would have all the filenames and their corresponding reviewers. not just for "sip" but for all those keywords.contained in file2. Any help would be much appreciated. ThanksKris Link to comment Share on other sites More sharing options...
randallc Posted January 18, 2008 Share Posted January 18, 2008 (edited) OK! here you go.. ; sipper1.au3 #include<file.au3> Local $sFile1 = @ScriptDir & "\file1.txt", $sFile2 = @ScriptDir & "\file2.txt", $sFileResult = @ScriptDir & "\results.txt", $c = FileDelete($sFileResult) Local $arFile1, $arResults[1],$sSearch,$c=_FileReadToArray($sFile1,$arFile1) ReDim $arResults[UBound($arFile1)] ;find Array of search terms first; $sFileRead2 = FileRead($sFile2) $arSearchTerms = StringRegExp($sFileRead2, "(?m)^%(.*)%.*$", 3) ;[could do this looping through the file2 array and using "stringbetween"] $arFile2 = StringRegExp($sFileRead2, "(?m)^%.*%(.*$)", 3);[could do this looping through the file2 array and using "stringbetween"] ;loop through lines of file1 For $i = 1 To UBound($arFile1) - 1 ;loop through $arSearchTerms for checking each line For $j = 0 To UBound($arSearchTerms) - 1 $sSearch=StringReplace($arSearchTerms[$j],"/","") If StringInStr($arFile1[$i], "\"&$sSearch&"\") or StringInStr($arFile1[$i], "/"&$sSearch&"/") Then $arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") ExitLoop EndIf Next Next _FileWriteFromArray($sFileResult, $arResults) ; bug with blank first line fixed in 3.2.11.0 Run("notepad " & $sFileResult)oÝ÷ جµ§u©e2jëh×6$arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") - I had "$i" near the end instaed of "%j"] Edited January 18, 2008 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 OK! here you go.. ; sipper1.au3 #include<file.au3> Local $sFile1 = @ScriptDir & "\file1.txt", $sFile2 = @ScriptDir & "\file2.txt", $sFileResult = @ScriptDir & "\results.txt", $c = FileDelete($sFileResult) Local $arFile1, $arResults[1],$sSearch,$c=_FileReadToArray($sFile1,$arFile1) ReDim $arResults[UBound($arFile1)] ;find Array of search terms first; $sFileRead2 = FileRead($sFile2) $arSearchTerms = StringRegExp($sFileRead2, "(?m)^%(.*)%.*$", 3) ;[could do this looping through the file2 array and using "stringbetween"] $arFile2 = StringRegExp($sFileRead2, "(?m)^%.*%(.*$)", 3);[could do this looping through the file2 array and using "stringbetween"] ;loop through lines of file1 For $i = 1 To UBound($arFile1) - 1 ;loop through $arSearchTerms for checking each line For $j = 0 To UBound($arSearchTerms) - 1 $sSearch=StringReplace($arSearchTerms[$j],"/","") If StringInStr($arFile1[$i], "\"&$sSearch&"\") or StringInStr($arFile1[$i], "/"&$sSearch&"/") Then $arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") ExitLoop EndIf Next Next _FileWriteFromArray($sFileResult, $arResults) ; bug with blank first line fixed in 3.2.11.0 Run("notepad " & $sFileResult)oÝ÷ جµ§u©e2jëh×6$arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") - I had "$i" near the end instaed of "%j"] Thanks, but theres still a problem. i get an error when i run it. attached screenshot will show u the exact error. am just learning these file concepts , and frankly your script is still firing my brain pistons. Help me out. ! Thanks, Kris Link to comment Share on other sites More sharing options...
kris06 Posted January 18, 2008 Author Share Posted January 18, 2008 Hello Randal, The Code works perfectly. I couldnt have asked for more !! Thanks for all the efforts, i just tweaked the search string in your code and i got wht i wanted. Once again thanks !! Rgds, Krishna #include<file.au3> Local $sFile1 = @ScriptDir & "\file1.txt", $sFile2 = @ScriptDir & "\file2.txt", $sFileResult = @ScriptDir & "\results.txt", $c = FileDelete($sFileResult) Local $arFile1, $arResults[1],$sSearch,$c=_FileReadToArray($sFile1,$arFile1) ReDim $arResults[UBound($arFile1)] ;find Array of search terms first; $sFileRead2 = FileRead($sFile2) $arSearchTerms = StringRegExp($sFileRead2, "(?m)^%(.*)%.*$", 3);[could do this looping through the file2 array and using "stringbetween"] $arFile2 = StringRegExp($sFileRead2, "(?m)^%.*%(.*$)", 3);[could do this looping through the file2 array and using "stringbetween"] ;loop through lines of file1 For $i = 1 To UBound($arFile1) - 1 ;loop through $arSearchTerms for checking each line For $j = 0 To UBound($arSearchTerms) - 1 $sSearch=StringReplace($arSearchTerms[$j],"/","") If StringInStr($arFile1[$i], "\"&$sSearch) or StringInStr($arFile1[$i], "/"&$sSearch) Then $arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") ExitLoop EndIf Next Next _FileWriteFromArray($sFileResult, $arResults); bug with blank first line fixed in 3.2.11.0 Run("notepad " & $sFileResult) ;$arResults[$i] = $arFile1[$i] & @TAB& @TAB& StringReplace($arFile2[$j],@TAB," ") Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now