electrobins Posted October 3, 2006 Share Posted October 3, 2006 I need to create an autoIT exe file which can copy a perticular line from a txt file say copy.txt & paste it to another file say paste.txt at the end of a perticular line saying VALUE at the begining of the line.Right now I am able to copy & paste, but I can paste only at the begining of file but not at the specific location.I am attaching the required files-test.au3, copy.txt & paste.txt.Any AutoIT expert, Please help me.test.au3paste.txtcopy.txt Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 3, 2006 Moderators Share Posted October 3, 2006 Many ways to do it, _FileReadToArray() / _FileCountLines() / etc... and so on... here's a way with StringRegExp() (soon to be broken I'm sure )$FileRead = FileRead('Copy.txt') $aArray = StringRegExp($FileRead, '(?i:scm=)(.*?)\n', 3) If IsArray($aArray) Then FileWriteLine('Paste.txt', _ ' VALUE "' & StringTrimRight($aArray[0], 1) & '"') EndIf Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
randallc Posted October 3, 2006 Share Posted October 3, 2006 or.. look at parms for _FileWriteToLine 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...
electrobins Posted October 3, 2006 Author Share Posted October 3, 2006 or..look at parms for _FileWriteToLine Best, randallYes, you are right.We can give the line number to function _FileWriteToLine, but this line number differs everytime, it depends on a perticular string.Is there any way to first search the perticular word (in my case it is "special build"), then get that line number & paste the text at the end of that line? One more point, I want to clarify here is that the string may appear many times in the file & this line counter of occurance of the string in the file should be the last occurance.Please guide me. Link to comment Share on other sites More sharing options...
randallc Posted October 3, 2006 Share Posted October 3, 2006 Yes, you are right. We can give the line number to function _FileWriteToLine, but this line number differs everytime, it depends on a perticular string. Is there any way to first search the perticular word (in my case it is "special build"), then get that line number & paste the text at the end of that line? One more point, I want to clarify here is that the string may appear many times in the file & this line counter of occurance of the string in the file should be the last occurance. Please guide me.Maybe modify this; $filepasteread = FileRead("paste2.txt") $i_Pos = StringInStr($filepasteread, "specialbuild", 0, -1) $s_StartFile = StringLeft($filepasteread, $i_Pos) StringReplace($s_StartFile, @LF, " ") $numLines = @extended $file = FileOpen("copy.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $check_rc = FileReadLine($file) If @error = -1 Then ExitLoop If StringInStr($check_rc, "scm=") Then _FileWriteToLine("paste2.txt", $numLines + 2, $check_rc, 0) WEnd FileClose($file)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...
electrobins Posted October 3, 2006 Author Share Posted October 3, 2006 Thanks, Randall I will try your solution tomorrow, since it is almost midnight. Thanks again, I will paste my outcome. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 3, 2006 Moderators Share Posted October 3, 2006 (edited) Hmm, I don't get why you have to make it so bulky... _FileReadToArray() + StringInStr() + FileWriteLine() will work fine, as well as the option I gave. Edit:$FileRead = FileRead('Copy.txt') $aArray = StringRegExp($FileRead, '(?i:scm=)(.*?)\n', 3) If IsArray($aArray) Then For $iCC = 0 To UBound($aArray) - 1 FileWriteLine('Paste.txt', _ ' VALUE "' & StringTrimRight($aArray[$aArray], 1) & '"') Next EndIfoÝ÷ ØØy©Ý²)©áÐuçZrÚ&jG¬º·ébè¬iËnjYrnV§ØZ·*.j·°®+bhjwb~z-¶ènV§«¢+ØÀÌØí¥±Iô¥±I Ìäí ½Áä¹ÑáÐÌäì¤(ÀÌØíÉÉäôMÑÉ¥¹IáÀ ÀÌØí¥±I°Ìäì ý¤éÍ´ô¤ ¸¨ü¤ÀäÈí¸Ìäì°Ì¤)%%ÍÉÉä ÀÌØíÉÉä¤Q¡¸(%1½°ÀÌØíMÁ±¥ÐôMÑÉ¥¹MÁ±¥Ð¡MÑÉ¥¹MÑÉ¥Á H¡¥±I ÌäíAÍѹÑáÐÌä줤°1¤(%%MÑÉ¥¹MÑÉ¥Á]L ÀÌØíMÁ±¥ÑlÀÌØíMÁ±¥ÑlÁut°à¤±ÐìÐìÌäìÌäìQ¡¸($%¥±]É¥Ñ1¥¹ ÌäíAÍѹÑáÐÌäì° I1¤(%¹%(%½ÈÀÌØí¥ ôÄQ¼U ½Õ¹ ÀÌØíÉÉ䤴Ä($%¥±]É¥Ñ1¥¹ ÌäíAÍѹÑáÐÌäì°|($$$ÌäìY1UÅÕ½ÐìÌäìµÀìMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÉÉålÀÌØíÉÉåt°Ä¤µÀìÌäìÅÕ½ÐìÌäì¤(%9áÐ)¹% Edited October 3, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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