AutoHotkey Community

It is currently May 27th, 2012, 6:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: February 12th, 2012, 12:45 am 
If I run the following:
Code:
FileRead, OutputVar, filein.txt
Sort, OutputVar, N
;--------------------------- Regex here.
FileAppend, %OutputVar%, fileout.txt


I want to run a loop read but only on the lines which begin with an integer.

Code:
Loop, read, fileout.txt
{
   Pos := RegExMatch(A_LoopReadLine, """([^""]*)""", var)
   FileAppend, %var1%`n, tmp2.txt
}


It would be better if I could run RegEx after the Sort, instead of creating a "fileout" then doing a loop read. NOTE: The input file HAS to be sorted numerically before RegEx.

Thanks for your help! :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2012, 1:19 am 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
you mean like this?
Code:
read_me := A_Desktop . "\New Text Document.txt"
h_file := FileOpen(read_me, 3)

if isObject(h_file) {
   Loop {
      line := h_file.ReadLine()
      if % RegexMatch(line, "^\d")
         new_file .= line
   } Until h_file.AtEOF
}
else {
   MsgBox unable to read file
   ExitApp
}

Sort, new_file, N
;FileAppend new_file content here


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2012, 1:32 am 
Wow, your code is impressive. After a few tries I came up with this:
Code:
file = New Text Document.txt
FileRead, OutputVar, %file%
Sort, OutputVar, N
FileAppend, %OutputVar%, tmp.txt
loop, read, tmp.txt
{
   StringLeft, int_check, A_LoopReadLine, 1
   if int_check is number
      ;FileAppend new_file content here
}


Thanks for your help!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], migz99, sjc1000 and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group