AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TF: Text file & Variables/String Library v3.3 [lib]
Goto page Previous  1, 2, 3 ... 5, 6, 7 ... 11, 12, 13  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Mon Nov 30, 2009 6:52 pm    Post subject: Reply with quote

hugov, Wonderful Project
Thanks for sharing
Very useful Exclamation Laughing
Nice addition to my UltraEdit features/functions

I used both v2 and v3 regularly and recommend to users
who need it's detailed filtering/replacing etc ...

Great documentation too. Idea

Look forward to use any future work of yours:!: Rolling Eyes
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Nov 30, 2009 7:46 pm    Post subject: Reply with quote

@txquestor: thanks, glad to hear you find it useful. I see you are man (or woman) of good taste, you like UltraEdit (I do too) Wink I've seen you recommending it a few times, thanks for that as well.

The documentation was quite a bit of work and could probably still be improved, I'm not sure if I would want to do it again in the same way.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Dec 09, 2009 5:34 pm    Post subject: Reply with quote

Update v3.1:

- Rewrite of TF_Find. Can now return multiple lines (like TF_Findlines used to), but not only line numbers but the entire line (text) of the found lines so it can be used as a basic grep.

- Now uses RegExMatch and no longer IfInString

- Deprecated: TF_FindLines (see change TF_Find). Kept in for backwards compatibility

TF_Find(Lines) compatibility note:

- Because the old TF_Find(Lines) did not use RegExMatch you may need to rewrite some of your SearchText parameters. This means that if you used "special" characters which have a special meaning in a RegEx: \.*?+[{|()^$ they must be preceded by a backslash to be seen as literal. For example, \. is a literal period and \\ is a literal backslash. Escaping can be avoided by using \Q...\E. For example: \QLiteral Text\E. See http://www.autohotkey.com/docs/commands/RegExMatch.htm for further information.

- The CaseSensitive paramaters has been dropped, if you used that update your call to TF_Find I'm affraid
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Dec 23, 2009 8:42 pm    Post subject: Reply with quote

deleted
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum


Last edited by SoLong&Thx4AllTheFish on Fri Jan 15, 2010 5:01 pm; edited 1 time in total
Back to top
View user's profile Send private message
gregW5865



Joined: 28 Dec 2009
Posts: 5
Location: Torrance, CA

PostPosted: Mon Dec 28, 2009 9:05 pm    Post subject: TF_Replace with variables Reply with quote

Thanks for the work on the TF library. It has simplified what I am trying to do. I have hit a snag and hoping someone can help.
I am trying to change dates in a file that are in mm/dd format and I want it in yyyy-mm-dd format.
I have a variable:
year= 2009
Then I try to put the year in front of the month and I can't figure out the syntax. I've tried variations on this:
TF_Replace(f,"01/",%Year% "-01") or
TF_Replace(f,"01/",% %Year% ."-01")
I get errors regarding needing quote or ")" but I can't figure it out.
Any help is greatly appreciated.
_________________
Greg W
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Dec 28, 2009 9:24 pm    Post subject: Re: TF_Replace with variables Reply with quote

So you have this mm/dd and you want it in yyyy-mm-dd

So 01/02 -> 2009-01-02, that means TF_Replace must be
Code:
TF_Replace(f,"01/02","2009-01-02") ; note the use of ! if you want to overwrite the source file

So translating that to variables would be
Code:
TF_Replace(f,"01/", year . "-01-") ; note the use of ! if you want to overwrite the source file


Note: you could also use a regexp, could be something like
Code:
TF_RegExReplace(f,"(\d\d)\\(\d\d)", year . "-$1-$2") ; note the use of ! if you want to overwrite the source file
(fiddling with regex can be difficult so may not be what you want to look into just yet if you start with AHK)
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
gregW5865



Joined: 28 Dec 2009
Posts: 5
Location: Torrance, CA

PostPosted: Tue Dec 29, 2009 3:34 am    Post subject: Re: TF_Replace with variables Reply with quote

Thanks for the help. That did the trick.
_________________
Greg W
Back to top
View user's profile Send private message
gregW5865



Joined: 28 Dec 2009
Posts: 5
Location: Torrance, CA

PostPosted: Wed Dec 30, 2009 5:38 am    Post subject: Insert Suffix Reply with quote

I'm stuck again.
I have the main file I am working (f) with and a second file (s) with the same number of lines. I want to add line one from the second file to line one of the first file and then repeat for each line.
Code:

f= !first.txt
s= !second.txt

GetLine:=TF_Find(s,"","","",0,1) 
TF_InsertSuffix(f,"","", TF_ReadLines(GetLine,"","",0) . "@")


I also tried this:
Code:

GetLine:=TF_Find(s,"","","",0,1) ;
Line= % TF_ReadLines(GetLine,"","",0) ;
TF_InsertSuffix(f,"","", %line% . "@") ;


I get the desired results for the first line but all other lines only contain lines from the second file.

Thanks for your help
_________________
Greg W
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Dec 30, 2009 6:43 am    Post subject: Reply with quote

Doesn't TF_ConCat fit the bill here:
http://www.autohotkey.net/~hugov/tf-lib.htm#TF_ConCat

Output wrote:
Line 1 file 1 Line 1 File 2
Line 2 file 1 Line 2 File 2
Line 3 file 1 Line 3 File 2
etc

_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
gregW5865



Joined: 28 Dec 2009
Posts: 5
Location: Torrance, CA

PostPosted: Wed Dec 30, 2009 7:38 am    Post subject: Insert Suffix Reply with quote

I feel real stupid Embarassed I read through the list several times and over looked that one. Thanks for the quick reply and the great work on the library.
_________________
Greg W
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Dec 30, 2009 7:49 am    Post subject: Reply with quote

Don't feel bad, I'm glad someone is using it Wink The names are a bit peculiar at times, ConCat it probably doesn't ring a bell with many people. If you think there is something missing I'm always open for suggestions so feel free to ask.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
gregW5865



Joined: 28 Dec 2009
Posts: 5
Location: Torrance, CA

PostPosted: Sat Jan 02, 2010 5:51 am    Post subject: Problem subtracting dates in a file Reply with quote

I'm stuck again...Just when I thought I was finished Very Happy
I have a file with dates in the yyyymmddhhmmss format like this and that is all the file contains.
20100103080000
20100103090000
20100103210000
20100104025800
20100103080000

I want to subtract 2 minutes from each line. I have tried various options using EnvSub but I just don't get it. I need help with setting up the varaibles and which TF_ command would be best.

Thanks for your help.
Greg
_________________
Greg W
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Jan 02, 2010 8:19 am    Post subject: Reply with quote

Try this. The first bit is an example how math with time works, the second bit is a possible solution. In this case I wouldn't use any TF functions in particular but you could use TF_Save
Code:
;  yyyymmddhhmmss
t=20100103210000 ; original
x=20100103205800 ; should be become
t += -2, Minutes
MsgBox % t "`n" x

; so if you have a file with only times, I suggest not to use TF as such
; but rather a fileread, loop and TF_Save (or filedelete and a fileappend)

FileRead, original, file.txt
Loop, parse, original, `n, `r
   {
    if (A_LoopField <> "")
      {
       NewTime:=A_LoopField
       NewTime += -2, Minutes
            Output .= NewTime "`n"
      }
    NewTime= ; just to be sure
   }
StringTrimRight, Output, Output, 1 ; trim trailing newline
TF_Save(Output, "file.txt", 0) ; will make file_copy.txt so you can test, remove 0 if OK and it will overwrite
Back to top
Tom



Joined: 20 Dec 2009
Posts: 15

PostPosted: Sun Jan 03, 2010 2:17 pm    Post subject: Reply with quote

Hi

I have what I hope are 2 simple questions about TF.ahk

I'm currently using this to read the first line that matches my value 'disengage':
Code:
GetLine:=TF_Find(ReceivedData,"","","disengage",1,1)

This works well and outputs the first matching line to GetLine. I then filter that line and no problems with this Smile

I'm now looking to do some thing similar but instead of matching just one line I need it to match on multiple lines and, if possible, join the results together.

The data I receive is similar to this:
Code:
aMode,,0000003e,4
aMode,,0000003e,A
aMode,,0000003e,C
aMode,,0000003e,3

The command at the beginning stays the same (aMode) there is usually the double commas followed by an ID field and finally the values I want to capture..

The example shows 4 lines, but it could be upto 12 lines.

How would I capture this and return the values to a variable.
eg: var = 4AC3


Last one:
Currently I'm only using "TF_Find", what can I strip from TF.ahk to reduce the size of the file included in my script ?

Many Thanks
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 03, 2010 8:28 pm    Post subject: Reply with quote

1) If you strip TF_Find to its bare mininum for YOUR purposes, e.g. just return the first found line it is this, note the new name so it doesn't conflict with the TF lib
Code:
test=
(
1 a
2 b
3 c
4 d
)

MsgBox % XTF_Find(test,"b")

XTF_Find(Text, SearchText = "")
   {
    If (RegExMatch(Text, SearchText) < 1)
       Return "0" ; SearchText not in file or error, do nothing
    Loop, Parse, Text, `n
      {
          If (RegExMatch(A_LoopField, SearchText) > 0)
             {
               Return A_LoopField
               Break
            }   
      }
   }


2) you're probably better of writing your own function to get that data it would be faster and easier, UNLESS the final columns always has the same position e.g. it is always column 15, if that is the case you can use TF_ColGet and simply to a stringreplace `n to remove the newline chars.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 5, 6, 7 ... 11, 12, 13  Next
Page 6 of 13

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group