{"id":13804753,"url":"https://github.com/hi5/TF","last_synced_at":"2025-05-13T18:32:45.621Z","repository":{"id":11745999,"uuid":"14275217","full_name":"hi5/TF","owner":"hi5","description":"AutoHotkey library for Text files \u0026 Variables (strings)","archived":false,"fork":false,"pushed_at":"2020-12-12T22:26:08.000Z","size":52,"stargazers_count":143,"open_issues_count":0,"forks_count":38,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-02-20T09:15:52.956Z","etag":null,"topics":["autohotkey","find","join","merge","read","regexreplace","remove-lines","reverse-lines","sort","split","tail","text-manipulation","texttools","trim","wrap"],"latest_commit_sha":null,"homepage":"https://autohotkey.com/boards/viewtopic.php?f=6\u0026t=576","language":"AutoHotkey","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hi5.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-10T11:27:53.000Z","updated_at":"2025-01-28T08:13:24.000Z","dependencies_parsed_at":"2022-09-10T18:21:01.350Z","dependency_job_id":null,"html_url":"https://github.com/hi5/TF","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2FTF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2FTF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2FTF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2FTF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hi5","download_url":"https://codeload.github.com/hi5/TF/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254003441,"owners_count":21997887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autohotkey","find","join","merge","read","regexreplace","remove-lines","reverse-lines","sort","split","tail","text-manipulation","texttools","trim","wrap"],"created_at":"2024-08-04T01:00:53.631Z","updated_at":"2025-05-13T18:32:45.276Z","avatar_url":"https://github.com/hi5.png","language":"AutoHotkey","readme":"# TF: Textfile \u0026 String Library for AutoHotkey [lib] - v3.8\n\n__A \"Swiss Army Knife\" library for Text (files)__\n\n## Introduction\n\nAs the name suggest this is an AutoHotkey (AHK) Library with a number of functions to \"manipulate\" **text**,\nboth **files** such as \\*.txt, \\*.ahk, \\*.html, \\*.css etc AND **Strings** (or variables). For example\nyou can delete specific lines, replace words or specific lines, number lines, remove or insert columns\nof text, etc. See the list of functions below for a complete overview.\n\nIt is **not** useful for binary files or data such as MS Office files, PDFs, EXEcutables, images etc.\n(Tip: search the AHK forum for \"binread\" to find some pointers on how to read, write and \"edit\" binary files.)\n\n## Functions\n\n1.  [TF](#TF)\n2.  [TF_Save](#TF_Save)\n3.  [TF_CountLines](#TF_CountLines)\n4.  [TF_Count](#TF_Count) *1\n5.  [TF_ReadLines](#TF_ReadLines)\n6.  [TF_Tail](#TF_Tail)\n7.  [TF_Replace](#TF_Replace)\n8.  [TF_ReplaceInLines](#TF_ReplaceInLines)\n9.  [TF_RegExReplace](#TF_RegExReplace)\n10. [TF_RegExReplaceInLines](#TF_RegExReplaceInLines)\n11. [TF_RemoveLines](#TF_RemoveLines)\n12. [TF_RemoveBlankLines](#TF_RemoveBlankLines)\n13. [TF_RemoveDuplicateLines](#TF_RemoveDuplicateLines)\n14. [TF_InsertLine](#TF_InsertLine)\n15. [TF_ReplaceLine](#TF_ReplaceLine)\n16. [TF_InsertPrefix](#TF_InsertPrefix)\n17. [TF_InsertSuffix](#TF_InsertSuffix)\n18. [TF_TrimLeft](#TF_TrimLeft)\n19. [TF_TrimRight](#TF_TrimRight)\n20. [TF_AlignLeft](#TF_AlignLeft)\n21. [TF_AlignCenter](#TF_AlignCenter)\n22. [TF_AlignRight](#TF_AlignRight)\n23. [TF_LineNumber](#TF_LineNumber)\n24. [TF_ConCat](#TF_ConCat)\n25. [TF_ColGet](#TF_ColGet)\n26. [TF_ColPut](#TF_ColPut)\n27. [TF_ColCut](#TF_ColCut)\n28. [TF_ReverseLines](#TF_ReverseLines)\n29. [TF_Find](#TF_Find) (can be used as basic grep)\n30. [TF_SplitFileByLines](#TF_SplitFileByLines)\n31. [TF_SplitFileByText](#TF_SplitFileByText)\n32. [TF_Merge](#TF_Merge) *2\n33. [TF_Prepend](#TF_Prepend) *2\n34. [TF_Append](#TF_Append) *2\n35. [TF_Wrap](#TF_Wrap)\n36. [TF_WhiteSpace](#TF_WhiteSpace)\n37. [TF_Substract](#TF_Substract)\n38. [TF_RangeReplace](#TF_RangeReplace)\n39. [TF_MakeFile](#TF_MakeFile)\n40. [TF_Tab2Spaces](#TF_Tab2Spaces)\n41. [TF_Spaces2Tab](#TF_Spaces2Tab)\n42. [TF_Sort](#TF_Sort)\n43. [TF_Join](#TF_Join)\n\n**Notes**\n\n1. TF_Count does not support files and only works with variables.\n2. TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.\n \n**Concept**\n\nIt is important to understand a few basic concepts before you start working with the TF library:\n\n- If you pass on a file to a TF function the output will generally be a file (there are a few exceptions). By default it writes the output to a COPY of the input file, leaving the original input file intact.\n- You **can** overwrite the input file by using a ! as prefix. See \"Quick intro to Parameters\" and \"Textfile and the ! Prefix\" below for more details.\n- If you pass on a variable to a TF function the returned output will also be a variable.\n- Most TF Functions allow you to work on specific lines or sections of lines.\n- TF \"knows\" if something is a file or a variable, even if the variable passed on to TF is meant to represent a file. (This is done in the helper function TF_GetData for those interested).\n\nTo understand how to work with **files and variables** please read the \"Textfile and the ! Prefix\"\nand \"Files \u0026 Variables\" sections below.\n\n**File encoding, codepage**\n\nIf you experience TF is changing the file encoding (codepage) try to set the correct file encoding\nat the top of your script (or at least before you call a TF function) using the following AutoHotkey command:\nhttp://ahkscript.org/docs/commands/FileEncoding.htm\n\nPlease note, there is no way to determine the file encoding 100% accurately, even if a file\ncontains BOM. See the discussion about this topic and possibly useful additional functions\nat the AutoHotkey forum http://www.autohotkey.com/board/topic/95986-filegetencoding-filegetformat/\n(The result of these functions are simply a best guess assuming UTF-8 more common when BOM - https://en.wikipedia.org/wiki/Byte_Order_Mark - \nis missing).\n\n## How to \"install\" / use\n\nYou can either place TF.ahk in your LIB directory (see [http://ahkscript.org/docs/Functions.htm#lib](http://ahkscript.org/docs/Functions.htm#lib))\nor use #include (see [http://ahkscript.org/docs/commands/_Include.htm](http://ahkscript.org/docs/commands/_Include.htm))\n\nYou can find examples of most functions in the \"example script\" here\n[http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363](http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363)\n\n**Note:** Because most of these functions operate on a line by line basis they WILL be\nslower compared to a function or script which could operate on an entire file or\nvariable at once. Keep this in mind if you need to process many files/variables or very\nlarge files/variables in case speed is an issue.\n\n## Quick intro to Parameters\n\nAlmost all functions accept the following basic parameters:\n\n\u003ctable border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#C0C0C0\"\u003e\n      \u003ctr valign=\"top\"\u003e\n\t\t\u003ctd\u003e\u003cb\u003eParameter\u003c/b\u003e\u003c/td\u003e\n\t\t\u003ctd\u003e\u003cb\u003eMeaning\u003c/b\u003e\u003c/td\u003e\n\t  \u003c/tr\u003e\t\n\t  \u003ctr valign=\"top\"\u003e\n\t    \u003ctd\u003eText\u003c/td\u003e\n\t    \u003ctd\u003eThe Filename (may include (absolute) path) to read from and save to (for all functions that write an output file).\u003cbr /\u003e\n         \u003cb\u003eNote:\u003c/b\u003e by default a filename_copy will be created, use the ! prefix if you want to OverWrite the TextFile (e.g. the source file)\u003cbr /\u003e\n\t     As of v3 \"Text\" can also be a variable or indeed text directly passed on to the function.\u003cbr /\u003e\n         See \u003ca href='#textfile-and-the--prefix'\u003eTextfile and the ! Prefix\u003c/a\u003e.\n\t    \u003c/td\u003e\n\t  \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003e! Prefix\u003c/td\u003e\n        \u003ctd\u003eIf Text starts with ! (eg: \"!c:\\sample.txt\") it will overwrite the text file, otherwise it will save the new file to a copy of the text file eg: Filename_copy.txt (All functions, apart from reading functions because there is no output file) \u003cbr /\u003e\n        \u003cb\u003eTip:\u003c/b\u003e you can use concatenation to add the !, e.g. \"!\" . \"Filename.txt\", see the examples in the AHK thread.\u003cbr /\u003e\n        Note: If Text is a variable, it can start with a ! as TF will detect automatically that it is not a file and will therefore not create a file but return the altered variable instead.\u003cbr /\u003e\n        See \u003ca href='#textfile-and-the--prefix'\u003eTextfile and the ! Prefix\u003c/a\u003e.\n\t    \u003c/td\u003e\n\t  \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003eLines\u003c/td\u003e\n        \u003ctd\u003eNumber of lines to read\u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003eStartLine\u003c/td\u003e\n        \u003ctd\u003eStart of Range (Almost all).\u003cbr /\u003e\n\t    See \u003ca href='#startline-endline-syntax'\u003e(StartLine, Endline) Syntax\u003c/a\u003e.\n\t    \u003c/td\u003e\n\t  \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003eEndLine\u003c/td\u003e\n        \u003ctd\u003eEnd of Range (Almost all).\u003cbr /\u003e\n  \t    See \u003ca href='#startline-endline-syntax'\u003e(StartLine, Endline) Syntax\u003c/a\u003e.\n\t    \u003c/td\u003e\n\t  \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003eSearchText\u003c/td\u003e\n        \u003ctd\u003eText to Find (Find / Replace functions)\u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr valign=\"top\"\u003e\n        \u003ctd\u003eReplaceText\u003c/td\u003e\n        \u003ctd\u003eText to Replace (Find / Replace functions)\u003c/td\u003e\n      \u003c/tr\u003e\n\u003c/table\u003e\n\n**Notes**\n\n1. Many functions also have specific parameters, see the description of each function below.\n2. **Backup files:** If a subdirectory \"backup\" is present in the directory of TextFile \na backup is made before overwriting the original file (both for file.txt and file_copy.txt)\nwith the BAK extension\n3. You can find examples of most functions in the \"example script\" here [http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363](http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363)\n\n### (StartLine, Endline) Syntax\n\nYou can pass on multiple lines (sections) by using the StartLine parameter.\n\nExamples:\n\n- (5) ; start from line 5 to the end (StartLine)\n- (5, 15) ; Section: lines 5 to 15 (StartLine, EndLine)\n- (\"5,13,45,67\", 135) ; Specific lines: 5,13,45,67, ignore 135 (\"StartLine\", Endline - **EndLine value is ignored**)\n- (\"5-13,45-51\", 135) ; Multiple sections of lines: 5 to 13, 45 to 51 ignore 135 (\"StartLine\", Endline - **EndLine value is ignored**)\n\nIncremental (EndLine will **not** be ignored) in the following cases:\n\n- (\"2+3\", 150) ; start with line 2, increment 3 up-to line 150 so 2,5,8,11,14 etc\n- (\"5+15\") ; start with line 5, increment 15 until end of file so 5,20,35 etc\n\nNegative Startline\n\n- A Negative startline value makes a TF function operate on the last X lines.\n- TF_ColGet and TF_ColPut accept negative StartColumn parameter. This can be used to \"Get\" or \"Put\" text in the x-th \"column\" from the right\n\n### Textfile and the ! Prefix\n\nValid examples for using a Textfile:\n\n```autohotkey\nTF_(\"file.txt\", .... ; Process file.txt and write output to file_copy.txt\n\nF=file.txt ; ; Note how F is a variable, but AHK/TF will see it is meant to represent file.txt and write output to file_copy.txt\nTF_(F, .... ; Process file.txt and write output to file_copy.txt\nTF_(\"!file.txt\", .... ; Process file.txt and overwrite file.txt\n\nF=file.txt\nTF_(\"!\" . F, .... ; Process file.txt and overwrite file.txt\n\nF=!file.txt\nTF_(F, .... ; Process file.txt and overwrite file.txt\n\nIn a Loop, FilePattern:\nTF_(A_LoopFileName, .... ; Process file and write output to file_copy\nTF_(\"!\" . A_LoopFileName, .... ; Process file and overwrite file\n\nLoop, *.txt\n    {\n     TF_(A_LoopFileName, .... ; Process file and write output to file_copy\n    }\n```\n\nIf you want to use multiple TF functions on a single file it is advised to use the ! Prefix\n\n```autohotkey\nF=!file.txt \nTF_RemoveBlankLines(F)        ; remove all empty lines from file.txt and overwrite original file.txt\nTF_LineNumber(F)              ; add linenumbers to all lines and overwrite original file.txt\nTF_Replace(F, \"this\", \"that\") ; Replace the word \"this\" with \"that\" and overwrite original file.txt\n; So the original file.txt has undergone three changes\n```\n\n**Files \u0026 Variables (v3+)**\n\nYou can use TF functions directly on files as well as variables. \nBelow you will find some easy examples.\n\n**Introduced in v3: TF()**\n\nIn order to save you the trouble of using a fileread to read a file into\na variable and proceed to use various TF functions there is the TF()\nFunction.\n\n\n```autohotkey\nTF(\"pathtofile\", CreateGlobalVar=\"T\")\n```\n\nBy default it reads the contents of the file in a global variable named **t** and \nreturns it for further processing. By default it creates variable **t** if a variable\nname is **omitted** so if you do not like to use **t** you can use anything you like.\nIt is NOT mandatory to use TF(), you are welcome to use a fileread as well, TF() is \nmerely added for convenience as we will see in the examples below. TF() doesn't suddenly\nmake the TF library \"not standard compliant\" as some seem to think as it only creates a \nglobal variable if you use the TF() function.\n\n**Repeat:** You only have to use TF() if you want to read a file into a variable \nand use it on multiple TF_\\* Functions but it is NOT required.\n\nSee also [TF Lib Errors](#tf-lib-errors) below.\n\n**TF() Examples:**\n\n\n```autohotkey\nTF(\"file.txt\") ; will create global var t\nTF(\"file.txt\", \"MyVar\") ; will create global var MyVar\n```\n   \n**Examples on how to use files \u0026 variables with TF:**\n\n\n```autohotkey\n#Include tf.ahk\nTestFile= ; create variable\n(join`r`n\n1 Hi this\n2 a test variable\n3 to demonstrate\n4 how to \n5 use this\n6 new version\n7 of TF.AHK\n)\nFileDelete, TestFile.txt\nFileAppend, %TestFile%, TestFile.txt ; create file\nF=TestFile.txt ; just a shorthand code for TextFile.txt, so when\n; we are using 'F' below we are still passing on a TextFile, not a variable!\n\n; pass on file, read lines 5 to end of file:\nMsgBox % \"From File 1:`n\" TF_ReadLines(\"TestFile.txt\",5)\nMsgBox % \"From File 2:`n\" TF_ReadLines(F,5)              ; same\n\n; pass on variable, read lines 1 to 5\nMsgBox % \"From Variable 1:`n\" TF_ReadLines(TestFile,\"1-5\")  \nMsgBox % \"From Variable 2:`n\" TF_ReadLines(\"Hi`nthis`nis`na`ntest`nvariable`nfor`ntesting\",1,3) ; pass on string\n\n; Examples using TF(): (it will save you a FileRead if you want to work with Variables)\n\nTF(\"TestFile.txt\") ; read file, create global var t\nt:=TF_ReadLines(t,5) ; pass on global var t created by TF(), read lines 5 to end of file, assign result to t \nMsgBox % \"TF(), example 1:`n\" t\n\nTF(\"TestFile.txt\", \"MyVar\") ; read file, create global var MyVar\nMyVar:=TF_ReadLines(MyVar,5) ; pass on global var MyVar created by TF(), read lines 5 to end of file, assign result to MyVar\nMsgBox % \"TF(), example 2:`n\" MyVar\n\n; Note how we can use TF() here\nt:=TF_ReadLines(TF(\"TestFile.txt\"),5) ; pass on global var t created by TF(), read lines 5 to end of file, assign result to t \nMsgBox % \"TF(), example 3:`n\" t\n\nMyVar:=TF_ReadLines(TF(\"TestFile.txt\",\"MyVar\"),5) ; pass on global var t created by TF(), read lines 5 to end of file, assign result to t \nMsgBox % \"TF(), example 4:`n\" MyVar\n\nt:=TF_ReadLines(TF(F),5) ; pass on global var t created by TF(), read lines 5 to end of file, assign result to t\nt:=TF_ReverseLines(t,5) ; pass on global var t created by TF(), reverse lines, assign result to t\nMsgBox % \"TF(), example 5:`n\" t\n\n; Work directly with the clipboard or another other variable\nClipboard=Line 1`nLine 2`nLine 3`nLine 4`nLine 5`nLine 6`nLine 7`nLine 8\nClipboard:=TF_RemoveLines(Clipboard, 3, 6) ; remove lines 3 to 6\nMsgBox % \"Clipboard, example 6:`n\" Clipboard\n```\n    \n**Note** TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.\n\n**Common mistake(s):**\n\n\n```autohotkey\nMyVar:=TF_ReadLines(\"TestFile.txt\",5) ; this is wrong. It is AN INCORRECT EXAMPLE!\n```\n\nThe example above is incorrect: You pass on a file so the output is\ntestfile_copy.txt. In this case nothing meaningful is assigned to the\nvariable MyVar. Correct would be:\n\n\n```autohotkey\nMyVar:=TF_ReadLines(MyVar,5) ; this is OK\nMyVar:=TF_ReadLines(TF(\"TestFile.txt\",\"MyVar\"),5) ; this is OK\n```\n\n--------------------------------------------------------------------------\n\n# Functions and Examples\n\n**Note:** Some of these functions are very similar, but they are included in the library for ease of use ...\n\nYou can find examples of most functions in the \"example script\" here [http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363](http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363)\n\n\u003ca name=\"TF\"\u003e\u003c/a\u003e\n\n**TF(TextFile, CreateGlobalVar=\"T\")**\n\n- Purpose: Read contents of file to create global variable, **T** by default.\n- Parameters: TextFile, CreateGlobalVar (=preferred name of global variable)\n- Credits: See TF thread \u0026 discussion http://www.autohotkey.com/forum/viewtopic.php?p=313120#313120\n\nNote: see background info and examples above at [Files and Variables](#FilesAndVariables).\n\n\u003ca name=\"TF_CountLines\"\u003e\u003c/a\u003e\n\n**TF_CountLines(Text)**\n\n- Purpose: Returns the number of lines in a file or variable\n- Parameters: Text\n- Credits: SKAN\n\n\n```autohotkey\nMsgBox % TF_CountLines(\"File.txt\") ; show the number of lines of file in a MsgBox\nLines:=TF_CountLines(\"File.txt\") ; store the number of lines of file in a variable\n```\n\n\u003ca name=\"TF_Count\"\u003e\u003c/a\u003e    \n\n**TF_Count(String, Char)**\n\n- Purpose: Count the number of occurrence of Char using StringReplace\n- Parameters: String, Char\n\nNotes: do **not** use it to count lines (using `n) because it will return an incorrect value,\nuse TF_CountLines for counting lines. TF_Count does not support files and only works with variables.\n\n\n```autohotkey\nMsgBox % TF_Count(\"Hello this is an example\", \"i\") ; count how many i's there are in the string\n```\n\n\u003ca name=\"TF_ReadLines\"\u003e\u003c/a\u003e\n\n**TF_ReadLines(Text, StartLine = 1, EndLine = 0, RemoveTrailing = 0)**\n\n- Purpose: Return the specified lines, can be used to read sections of a file or variable.\n- Parameters: Text, StartLine, EndLine\n\nNote: by default it will add a newline character to the last line, so if you want to \nappend new data you don't have to start it with a newline char. If you don't want\nthat use RemoveTrailing = 1.\n\n\n```autohotkey\nMsgBox % TF_ReadLines(\"File.txt\",5) ; Read lines 5 to end of file, show result in a MsgBox\nLines:=TF_ReadLines(\"File.txt\",5) ; Read lines 5 to end of file, store result in variable\nMsgBox % TF_ReadLines(\"File.txt\",5,0,1) ; 0 for end line indicates until end of file, remove trailing empty line.\n```\n\n\u003ca name=\"TF_Tail\"\u003e\u003c/a\u003e\n\n**TF_Tail(Text, Lines = 1, RemoveTrailing = 0, ReturnEmpty = 1)**\n\n- Purpose: Read last X lines from file or variable\n- Parameters: Text, Lines, RemoveTrailing (0 or 1), ReturnEmpty (0 or 1)\n- Credits: incl. ideas from Tuncay\n\nNotes:\n\n1.  Lines can be a negative number: -1 will get the second to last line.\n    If you use a negative number it will ALWAYS retrieve a SINGLE line\n2.  By default TF_Tail will return empty lines, if you don't want that\n    use ReturnEmpty = 0\n3.  By default TF_Tail will add a newline character to the last line, so\n    if you want to append new data to the returned data you don't have\n    to start it with a newline char. If you don't want that use\n    RemoveTrailing = 1\n\n\n```autohotkey\nMsgBox % TF_Tail(\"File.txt\", 3) ; get the last three lines\nMsgBox % TF_Tail(\"File.txt\", -2) ; get second to last line, negative values only return one line\nMsgBox % TF_Tail(\"File.txt\", 5, 0, 0) ; return the last five lines, with trailing new line and excluding empty lines\n```\n\n\u003ca name=\"TF_Replace\"\u003e\u003c/a\u003e\n\n**TF_Replace(Text, SearchText, Replacement=\"\")**\n\n- Purpose: Find and Replace text in entire file (using StringReplace)\n- Parameters: Text, SearchText, Replacement\n\n\n```autohotkey\nTF_Replace(\"File.txt\",\"key\",\"lock\")            ; pass on a file, replace the word \"key\" with \"lock\" in file_copy.txt\n```\n\n\u003ca name=\"TF_ReplaceInLines\"\u003e\u003c/a\u003e\n\n**TF_ReplaceInLines(Text, StartLine = 1, EndLine = 0, SearchText = \"\", ReplaceText = \"\")**\n\n- Purpose: Find and Replace text on specific lines (using StringReplace)\n- Parameters: Text, StartLine, EndLine, SearchText, ReplaceText\n\n\n```autohotkey\nTF_ReplaceInLines(\"!File.txt\",\"1,3,9\",\"\",\"key\",\"lock\") ;  update source file, replace \"key\" with \"lock\" in lines 1, 3 and 9\n```\n\n\u003ca name=\"TF_RegExReplace\"\u003e\u003c/a\u003e\n\n**TF_RegExReplace(Text, NeedleRegEx = \"\", Replacement = \"\")**\n\n- Purpose: Find and Replace text in entire file (using RegExReplace)\n- Parameters: Text, NeedleRegEx, Replacement\n\n\n```autohotkey\nTF_RegExReplace(\"File.txt\",\"im)^(.*)$\",\"[$1]\") ; pass on a file, wrap all lines in []\n```\n\n\u003ca name=\"TF_RegExReplaceInLines\"\u003e\u003c/a\u003e\n\n**TF_RegExReplaceInLines(Text, StartLine = 1, EndLine = 0, NeedleRegEx= \"\", Replacement = \"\")**\n\n- Purpose: Find and Replace text in specific lines (using RegExReplace)\n- Parameters: Text, StartLine, EndLine, NeedleRegEx, Replacement\n\n\n```autohotkey\nTF_RegExReplaceInLines(\"File.txt\",3,8,\" [a-z]{3} \",\" lock \")  ; replace any three letter word with \"lock\" in lines 3 to 8\n```\n\n\u003ca name=\"TF_RemoveLines\"\u003e\u003c/a\u003e\n\n**TF_RemoveLines(Text, StartLine = 1, EndLine = 0)**\n\n- Purpose: Remove specified lines from file\n- Parameters: Text, StartLine, EndLine\n\n\n```autohotkey\nTF_RemoveLines(\"File.txt\", 5, 10) ; remove lines 5 to 10 from file\n```\n\nNote: If you pass on a negative value for StartLine, example\nTF_RemoveLines(Text, -5, .... it will remove these lines from the end\nof Text, so -5 will remove the last five lines. The EndLine parameter is\nignored.\n\n\n\u003ca name=\"TF_RemoveBlankLines\"\u003e\u003c/a\u003e\n\n**TF_RemoveBlankLines(Text, StartLine = 1, EndLine = 0)**\n\n- Purpose: Remove blank lines from file (in specified section)\n- Parameters: Text, StartLine, EndLine\n\n\nNote: also removes lines with only tabs \u0026 spaces e.g. \"white space\"\n\n\n```autohotkey\nTF_RemoveBlankLines(\"File.txt\") ; remove blanklines in entire file\n```\n\n\n\u003ca name=\"TF_RemoveDuplicateLines\"\u003e\u003c/a\u003e\n\n**TF_RemoveDuplicateLines(Text, StartLine = 1, Endline = 0, Consecutive= 0, CaseSensitive = false)**\n\n- Purpose: Remove duplicate lines, optionally you can specify if they need to be Consecutive and / or Case sensitive\n- Parameters: Text, StartLine, EndLine, Consecutive (0 or 1), CaseSensitive (true or false)\n\n\n```autohotkey\nTF_RemoveDuplicateLines(\"File.txt\",\"\",\"\",1,false) ; remove only Consecutive duplicate lines\n```\n\n\u003ca name=\"TF_InsertLine\"\u003e\u003c/a\u003e\n\n**TF_InsertLine(Text, StartLine = 1, Endline = 0, InsertText = \"\")**\n\n- Purpose: Insert text in specified lines\n- Parameters: Text, StartLine, Endline, InsertText\n\n\n```autohotkey\nTF_InsertLine(\"File.txt\",\"2,4,9\",5,\"---\")     ; insert --- in lines 2 4 and 9. 5 is endline will be ignored\n```\n\n\u003ca name=\"TF_ReplaceLine\"\u003e\u003c/a\u003e\n\n**TF_ReplaceLine(Text, StartLine = 1, Endline = 0, ReplaceText = \"\")**\n\n- Purpose: Replace specified lines with new text\n- Parameters: Text, StartLine, Endline, ReplaceText\n\n\n```autohotkey\nTF_ReplaceLine(\"File.txt\",\"1+3\",8,\"---\")      ; replace lines 1 4 and 7. 8 is end line so no more lines are processed after \n```\n\n\u003ca name=\"TF_InsertPrefix\"\u003e\u003c/a\u003e\n\n**TF_InsertPrefix(Text, StartLine = 1, EndLine = 0, Text = \"\")**\n\n- Purpose: Insert a text at the BEGINNING of each of the specified lines\n- Parameters: Text, StartLine, Endline, Text\n\n\n```autohotkey\nTF_InsertPrefix(\"File.txt\",5,8, \"Hello \")          ; Prefix Hello in lines 5 to 8\n```\n\n\u003ca name=\"TF_InsertSuffix\"\u003e\u003c/a\u003e\n\n**TF_InsertSuffix(Text, StartLine = 1, EndLine = 0 , Text = \"\")**\n\n- Purpose: Append a text at the END of each of the specified lines\n- Parameters: Text, StartLine, Endline, Text\n\n\n```autohotkey\nTF_InsertSuffix(\"File.txt\",\"2-4,6-9\",\"\", \" Hello\")  ; Suffix Hello in lines 2 to 4 and 6 to 9\n```\n\n\u003ca name=\"TF_TrimLeft\"\u003e\u003c/a\u003e\n\n**TF_TrimLeft(Text, StartLine = 1, EndLine = 0, Count = 1)**\n\n- Purpose: Trim number of specified columns from specified lines\n- Parameters: Text, StartLine, Endline, Text, Count\n\n\n```autohotkey\nTF_TrimLeft(\"File.txt\",\"\",\"\",25)                    ; Trim Left 25 Characters of all lines\n```\n\n\u003ca name=\"TF_TrimRight\"\u003e\u003c/a\u003e\n\n**TF_TrimRight(Text, StartLine = 1, EndLine = 0, Count = 1)**\n\n- Purpose: Trim number of specified columns from specified lines\n- Parameters: Text, StartLine, Endline, Text, Count\n\n\n```autohotkey\nTF_TrimRight(\"File.txt\",\"4,6,8\",\"\",45)              ; Trim Right 45 Characters in lines 4, 6 and 8\n```\n\n\u003ca name=\"TF_AlignLeft\"\u003e\u003c/a\u003e\n\n**TF_AlignLeft(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)**\n\n- Purpose: Align lines according to number of specified columns\n- Parameters: Text, StartLine, Endline, Columns, Padding\n - incl. ideas from SKAN\n\nNote: Using the Align functions will not take into account any leading or trailing\nspaces a line had BEFORE processing. So all white space before and after the text\nis removed before the text is aligned.\n\n~~~~\nPadding = 0 Remove trailing white space\nPadding = 1 Keep trailing white space\n~~~~\n\n\n```autohotkey\nTF_AlignLeft(\"File.txt\",\"\",\"\",90, 1)    ; AlignLeft all lines, keep trailing white space\n```\n\n\u003ca name=\"TF_AlignCenter\"\u003e\u003c/a\u003e\n\n**TF_AlignCenter(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)**\n\n- Purpose: Align lines according to number of specified columns\n- Parameters: Text, Columns, StartLine, Endline, Text\n- uses some of SKAN functions\n\nNote: Using the Align functions will not take into account any leading or trailing\nspaces a line had BEFORE processing. So all white space before and after the text\nis removed before the text is aligned.\n\n~~~~\nSkip = 0 process empty lines, fill with spaces\nSkip = 1 skip empty lines, do not fill with spaces\n~~~~\n\n\n```autohotkey\nTF_AlignCenter(\"File.txt\",\"\",\"\",150, 1) ; AlignCenter, all lines skip empty lines, do not fill with spaces\n```\n\n\u003ca name=\"TF_AlignRight\"\u003e\u003c/a\u003e\n\n**TF_AlignRight(Text, StartLine = 1, EndLine = 0, Columns = 80, Skip = 0)**\n\n- Purpose: Align lines according to number of specified columns\n- Parameters: Text, Columns, StartLine, Endline, Skip (0 or 1)\n - uses some of SKAN functions\n\nNote: Using the Align functions will not take into account any leading\nor trailing spaces a line had BEFORE processing. So all white space\nbefore and after the text is removed before the text is aligned.\n\n~~~~\nSkip = 0 process empty lines, fill with spaces\nSkip = 1 skip empty lines, do not fill with spaces\n~~~~\n\n\n```autohotkey\nTF_AlignRight(\"File.txt\",\"\",\"\", 190, 0) ; AlignRight, all lines, do not skip empty lines fill them with spaces\n```\n\n\u003ca name=\"TF_LineNumber\"\u003e\u003c/a\u003e\n\n**TF_LineNumber(Text, Leading = 0, Restart = 0, Char = 0)**\n\n- Purpose: Insert line numbers before each line\n- Parameters: Text, Leading, Restart, Char\n- Credits: incl. ideas from ribbet.1\n\n~~~~\nLeading = 0 No padding with leading zeros\nLeading \u003e= 1 Include padding with leading zeros (001 v 1)\nRestart = restart counter after X lines (starting again at 1)\nChar = character to use for leading/padding. Default 0, but can be any character. Tip: use a space.\n~~~~\n\n\n```autohotkey\nTF_LineNumber(\"File.txt\",1,15,A_Space)  ; Add linenumbers, padding with spaces, linenumbers are aligned right because of space\n```\n\n\u003ca name=\"TF_ConCat\"\u003e\u003c/a\u003e\n\n**TF_ConCat(FirstTextFile, SecondTextFile, OutputFile, Blanks = 0, FirstPadMargin = 0, SecondPadMargin = 0)**\n\n- Purpose: Join Text files side by side (line1-from-file1 line1-from-file2 newline line2-from-file1 line2-from-file2 newline etc)\n- Parameters: FirstTextFile, SecondTextFile, OutputFile, Blanks, FirstPadMargin, SecondPadMargin\n\nBased on: CONCATenate text files, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip - Backup: http://www.retroarchive.org/garbo/pc/ts/\n\nWith TF_ConCat you can join Text files side by side. Blanks is number of blanks between lines.\nYou can pad blanks the right margin of either of the text files, for this use FirstPadMargin and SecondPadMargin.\n\n\u003ca name=\"TF_ColGet\"\u003e\u003c/a\u003e\n\n**TF_ColGet(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1, Skip = 0)**\n\n- Purpose: Get specified columns from text file\n- Parameters: Text, StartLine, EndLine, StartColumn, EndColumn, Skip (0 or 1)\n\n~~~~\nNote: A TAB character is 1 character so for files with TABS the column might not be where you expect it to be\nskip = 0, DO NOT skip lines shorter then startcolumn position\nskip = 1, skip lines shorter then startcolumn position\nTF_ColGet and TF_ColPut accept negative StartColumn parameter. This can be used to \"Get\" or \"Put\" text in the x-th \"column\" from the right\n~~~~\n\n\n```autohotkey\nTF_ColGet(\"File.txt\",\"\",\"\",2,13)    ; get columns 2 to 13 from all lines, so it removes all other columns from the file or variable\n```\n\n\u003ca name=\"TF_ColPut\"\u003e\u003c/a\u003e\n\n**TF_ColPut(Text, Startline = 1, EndLine = 0, StartColumn = 1, Text = \"\", Skip = 0)**\n\n- Purpose: Insert text at specified columns in text file\n- Parameters: Text, StartLine, EndLine, StartColumn, EndColumn, Skip (0 or 1)\n\nBased on: COLPUT.EXE \u0026 CUT.EXE, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip - Backup: http://www.retroarchive.org/garbo/pc/ts/\n\n~~~~\nNote: A TAB character is 1 character so for files with TABS the column might not be where you expect it to be\nskip = 0, DO NOT skip lines shorter then startcolumn position\nskip = 1, skip lines shorter then startcolumn position\nTF_ColGet and TF_ColPut accept negative StartColumn parameter. This can be used to \"Get\" or \"Put\" text in the x-th \"column\" from the right\n~~~~\n\n\n```autohotkey\nTF_ColPut(\"File.txt\",\"\",\"\",5, \"|\", 0) ; insert | in column 5 of all lines including empty lines (= | will be at column 1)\n```\n\n\u003ca name=\"TF_ColCut\"\u003e\u003c/a\u003e\n\n**TF_ColCut(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1)**\n\n- Purpose: Remove specified columns from text file\n- Parameters: Text, StartLine, EndLine, StartColumn, EndColumn\n\nBased on: COLPUT.EXE \u0026 CUT.EXE, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip\n\n\n```autohotkey\nTF_ColCut(\"File.txt\", \"2+2\", \"\", 4, 38)  ; remove columns 4 to 38 in lines 2 4 6 8 etc\n```\n\n\u003ca name=\"TF_ReverseLines\"\u003e\u003c/a\u003e\n\n**TF_ReverseLines(Text, StartLine = 1, EndLine = 0)**\n\n- Purpose: Reverse the order of specified lines\n- Parameters: Text, StartLine, EndLine\n\nNote: Startline parameter can not use specific lines, sections or incremental values here\n\n\n```autohotkey\nTF_ReverseLines(\"File.txt\",2,9) ; reverse lines 2 to 9\n```\n\n\u003ca name=\"TF_Find\"\u003e\u003c/a\u003e\n\n**TF_Find(Text, StartLine = 1, EndLine = 0, SearchText = \"\", ReturnFirst = 1, ReturnText = 0)**\n\n- Purpose: Find text using RegExMatch, return line(s), text or lines and text\n- Parameters: Text, StartLine, EndLine, SearchText, ReturnFirst, ReturnText\n\nTF_Find(Lines) uses Regular Expressions - This means that if you use certain characters which\nhave a special meaning in a RegEx: **\\\\.\\*?+[{|()\\^\\$** they must be preceded by a backslash\nto be seen as literal. For example, **\\\\.** is a literal period and **\\\\\\\\** is a literal backslash.\nEscaping can be avoided by using **\\\\Q**...**\\\\E**. For example: **\\\\QLiteral Text\\\\E**.\nSee [http://ahkscript.org/docs/commands/RegExMatch.htm](http://ahkscript.org/docs/commands/RegExMatch.htm)\nfor further information.\n\n~~~~\nReturnFirst = 0 return multiple lines \nReturnFirst = 1 return first line only\n\nReturnText = 0 return line numbers only\nReturnText = 1 return entire line (text). This simulates a basic grep feature\nReturnText = 2 return line numbers + entire line (text). This simulates a basic grep feature \n~~~~\n\n\n```autohotkey\nMsgBox % TF_Find(\"File.txt\", \"\", \"\", \"keys\") ; return first line number with keys in it\nMsgBox % TF_Find(\"File.txt\", \"\", \"\", \" c[a-z]+s \", 0, 1) ; find all lines with words that start with a c an end with an s\n```\n\n\u003ca name=\"TF_SplitFileByLines\"\u003e\u003c/a\u003e\n\n**TF_SplitFileByLines(Text, SplitAt, Prefix = \"file\", Extension = \"txt\", InFile = 1)**\n\n- Purpose: Split a text file in to several others based on number of lines\n- Parameters: Text, SplitAt (number), Prefix, Extension, InFile (0, 1 or 2)\n\n~~~~\nSplitAt = Number of lines (three methods, see below)\nPrefix . Extension = filenameAUTOINCREMENT.Extension (Example: part_ . txt)\nInFile = 0 skip line e.g. do not include the actual line in any of the output files\nInFile = 1 include line IN current file\nInFile = 2 include line IN next file\n~~~~\n\nNote: If you pass on a variable to TF_SplitFileByLines, the array size will be returned\nas Prefix0 and the array elements as Prefix1, Prefix2 etc similar to the AHK StringSplit\ncommand. The Extension parameter is ignored when using variables. Some characters are\nillegal such as - + @ % \u0026 \\* _ \\\\ / [ ] etc to use in Prefix, stick to a-z A-Z.\n\nOptions for \"SplitAt\" parameter:\n\n~~~~\na) One numerical value, example TF_SplitFileByLines(Text, \"25\", .... \n   will split text every 25 lines until the end \nb) Split at rotating line lengths using a dash \"-\" as separator, example TF_SplitFileByLines(Text, \"5-10-15\", .... \n   will split text at 5 10 15 lines, until the end so 5 lines, 10 lines, 15 lines, 5 lines, 10 lines etc\nc) Split at specific lines using a comma \",\" as separator, example TF_SplitFileByLines(Text, \"5,81,135\", .... \n   will split text at lines 5,81,135 until end of file (e.g. last file will be from line 135 until the end)\n~~~~\n\n\n```autohotkey\nTF_SplitFileByLines(\"File.txt\", 2, \"part\", \"zec\", 1) ; split source file every 2 lines, include 2nd line INFILE\n; illustrate use of variables and returned arrays:\nTF_SplitFileByLines(Variable, 2, \"part\", \"zec\", 1)\nMsgBox % \"Array size: \" . Part0 . \"`n1st array element: \"  Part1\n```\n\n\u003ca name=\"TF_SplitFileByText\"\u003e\u003c/a\u003e\n\n**TF_SplitFileByText(Text, SplitAt, Prefix = \"file\", Extension = \"txt\", InFile = 1)**\n\n- Purpose: Split a text file in to several others based on text\n- Parameters: Text, SplitAt (text, can be RegEx), Prefix, Extension, InFile (0, 1 or 2)\n\n~~~~\nSplitAt = Text, can be RegEx\nPrefix . Extension = filenameAUTOINCREMENT.Extension (Example: part_ . txt)\nInFile = 0 skip line e.g. do not include the actual line in any of the output files\nInFile = 1 include line IN current file\nInFile = 2 include line IN next file\n~~~~\n\nNote: If you pass on a variable to TF_SplitFileByLines, the array size will be returned\nas Prefix0 and the array elements as Prefix1, Prefix2 etc similar to the AHK StringSplit\ncommand. The Extension parameter is ignored when using variables. Some characters are \nillegal such as - + @ % \u0026 \\* _ \\\\ / [ ] etc to use in Prefix, stick to a-z A-Z.\n\n\n```autohotkey\nTF_SplitFileByText(\"File.txt\", \"button\", \"part\", \"zec\", 1)   ; split source file on every line with the word button, include that line INFILE\n; illustrate use of variables and returned arrays:\nTF_SplitFileByText(Variable, \"keyboard\", \"part\", \"zec\", 1)\nMsgBox % \"Array size: \" . Part0 . \"`n1st array element: \"  Part1\n```\n\n**TF_Merge(FileList, Separator = \"\\`n\", FileName = \"merged.txt\")**\n\n- Purpose: Merge several files into one\n- Parameters: FileList, Separator (what to put between two files, newline by default), FileName (name of output file, Prefix with a ! to overwrite target file)\n\nExample FileList:\n\n~~~~\nFileList=\n(\nfile1.txt\nfile2.txt\nfile3.txt\n)\n~~~~\n\nNote: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.\n\n\n```autohotkey\n; using Loop (files \u0026 folders) to create one quickly if you want to merge all TXT files for example:\nLoop, c:\\*.txt\n  FileList .= A_LoopFileFullPath \"`n\"\nTF_Merge(FileList) ; will create merged.txt, you can use ! to overwrite an existing file if you want\n\n; using FileSelectFile to select files to merged: (Thanks for asking Vitor, http://www.autohotkey.com/forum/viewtopic.php?p=335329#335329)\nFileDelete merged.txt ; not required\nFileList=\nFileSelectFile, FileList, M 1,,, *.txt ; M allows you to select multiple files while holding down the left ctrl button\nIf (ErrorLevel = 1) or (FileList = \"\")\n   ExitApp ; no files selected\nPath:=TF_ReadLines(FileList,1,1,1) ; the first line holds the directory of the selected files, so read path\nFileList:=TF_RemoveLines(FileList,1,1) ; remove path from filelist\nFileList:=TF_InsertPrefix(FileList, \"\", \"\", Path . \"\\\") ; make sure all files have full paths to file so the are read correctly\nTF_Merge(FileList) ; will create a file in the current script dir called merged.txt you can also specify another filename, take into account the filedelete merged.txt above\n\n; You could skip the Path:= step above by calling TF_ReadLines directly in TF_InsertPrefix, but you would have to delete the first line AFTER it like so:\n;FileList:=TF_InsertPrefix(FileList, \"\", \"\", TF_ReadLines(FileList,1,1,1) . \"\\\")\n;FileList:=TF_RemoveLines(FileList,1,1)\n```\n\n\u003ca name=\"TF_Prepend\"\u003e\u003c/a\u003e\n\n**TF_Prepend(File1, File2)**\n\n- Purpose: Prepend file1 to file2 (file2 is changed, uses TF_Merge)\n- Parameters: File1, File2\n\nNote: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.\n\n\u003ca name=\"TF_Append\"\u003e\u003c/a\u003e\n\n**TF_Append(File1, File2)**\n\n- Purpose: Append file1 to file2 (file2 is changed, uses TF_Merge)\n- Parameters: File1, File2\n\nNote: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.\n\n\u003ca name=\"TF_Wrap\"\u003e\u003c/a\u003e\n\n**TF_Wrap(Text, Columns = 80, AllowBreak = 0, StartLine = 1, EndLine = 0)**\n\n- Purpose: Wrap (specified) lines\n- Parameters: Text, Columns, AllowBreak (0 or 1), StartLine, EndLine\n\n~~~~\nAllowBreak = 0 will not \"break\" words, so it will take into account whole words and not chop them off. \nAllowBreak = 1 will break words\n~~~~\n\n\n```autohotkey\nTF_Wrap(\"File.txt\",60)            ; wrap at col 60\n```    \n\n\u003ca name=\"TF_WhiteSpace\"\u003e\u003c/a\u003e\n\n**TF_WhiteSpace(Text, RemoveLeading = 1, RemoveTrailing = 1, StartLine = 1, EndLine = 0)**\n\n- Purpose: Remove leading and/or trailing whitespace\n- Parameters: Text, RemoveLeading (0 or 1), RemoveTrailing (0 or 1), StartLine, EndLine\n\n~~~~\nRemoveLeading = 0  Do not remove leading white space of lines\nRemoveLeading = 1  Remove leading white space of lines\nRemoveTrailing = 0 Do not remove trailing white space of lines\nRemoveTrailing = 1 Remove trailing white space of lines       \n~~~~\n\n\n```autohotkey\nTF_WhiteSpace(\"File.txt\", 1, 0, \"5-10\") ; remove leading and keep trailing whitespace in lines 5 to 10\n```    \n\n\u003ca name=\"TF_Substract\"\u003e\u003c/a\u003e\n\n**TF_Substract(File1, File2, PartialMatch = 0)**\n\n- Purpose: Delete lines from file1 in file2 (using StringReplace)\n- Parameters: File1, File2, PartialMatch (0 or 1)\n\n~~~~\nFile2: you can use !file2 to overwrite file2 otherwise output is file2_copy.txt\nPartialMatch = 0 lines from file1 must appear as is, case insensitive \nPartialMatch = 1 allow for paRTIal match of line\nPartialMatch = 2 allow for paRTIal match of line, but remove entire line (uses RegEx, new as of v3.4)\n~~~~\n\n\u003ca name=\"TF_RangeReplace\"\u003e\u003c/a\u003e\n\n**TF_RangeReplace(Text, SearchTextBegin, SearchTextEnd, ReplaceText = \"\", CaseSensitive = \"False\", KeepBegin = 0, KeepEnd = 0)**\n\n- Purpose: A Range Replacement allows you to perform a replacement on text whose beginning and ending remains the same, but whose middle contents might change.\n- Parameters: SearchTextBegin, SearchTextEnd, ReplaceText, CaseSensitive (True or False), KeepBegin (0 or 1), KeepEnd (0 or 1)\n\nNote: Similar to \"BK Replace EM\" Range Replacement. It is basically an easier shortcut for a more complex RegExp.\n\n~~~~\nKeepBegin = 0 Remove SearchTextBegin from file\nKeepBegin = 1 Do not remove SearchTextBegin from file (saves you the trouble of putting it back in via ReplaceText)\nKeepEnd = 0 Remove SearchTextEnd from file\nKeepEnd = 1 Do not remove SearchTextEnd from file (saves you the trouble of putting it back in via ReplaceText)\n\nSearchTextBegin = \"\" e.g. empty means from START of File *1\nSearchTextEnd = \"\" e.g. empty means until END of File *1\n~~~~\n\n\\*1 if you pass on empty strings to SearchTextBegin and SearchTextEnd the entire file will \nreplaced with the replacement text.\nSearchTextBegin/End **can** be on the same line. Remember this LIB mainly operates on\na line by line basis. This Function only operates on the FIRST SearchTextBegin to \nthe FIRST SearchTextEnd it finds.\n\n\n```autohotkey\nRange=[insert this`ntext for the`nrange replace Text`ntest function]\nTF_RangeReplace(\"File.txt\", \"Create hotkeys for keyboard\", \"into an EXE file\", Range)\n```\n\n\u003ca name=\"TF_MakeFile\"\u003e\u003c/a\u003e\n\n**TF_MakeFile(Text, Lines = 1, Columns = 1, Fill = \" \")**\n\n- Purpose: Create file of X lines and Y columns, fill with space or other character(s)\n- Parameters: TextFile (new file to be created), Lines, Columns, Fill\n\nSometimes you need an \"empty\" file before you can start adding line numbers or putting data into a file.\n\n\u003ca name=\"TF_Tab2Spaces\"\u003e\u003c/a\u003e\n\n**TF_Tab2Spaces(Text, TabStop = 4, StartLine = 1, EndLine = 0)**\n\n- Purpose: Convert tabs to spaces, shorthand for TF_ReplaceInLines\n- Parameters: Text, TabStop, StartLine, EndLine\n- Credits: incl. ideas from infogulch\n\n~~~~\nTabStop = number of spaces to replace a TAB with, so 4 means a TAB will be replaced by 4 spaces\n~~~~\n\n\u003ca name=\"TF_Spaces2Tab\"\u003e\u003c/a\u003e\n\n**TF_Spaces2Tab(Text, TabStop = 4, StartLine = 1, EndLine = 0)**\n\n- Purpose: Convert tabs to spaces, shorthand for TF_ReplaceInLines\n- Parameters: Text, TabStop, StartLine, EndLine\n- Credits: incl. ideas from infogulch\n\n~~~~\nTabStop = number of spaces to replace with a TAB, so 4 means 4 spaces will be replaced by a TAB\n~~~~\n\n\u003ca name=\"TF_Sort\"\u003e\u003c/a\u003e\n\n**TF_Sort(Text, SortOptions = \"\", StartLine = 1, EndLine = 0)**\n\n- Purpose: Sort (section of) TextFile\n- Parameters: Text, SortOptions, StartLine, EndLine\n\n~~~~\nSortOptions: use the SORT options http://ahkscript.org/docs/commands/Sort.htm\n~~~~\n\nNote: StartLine can not have multiple sections, increments or multiple lines in this case.\nWhen dealing with variables/strings instead of text files the native AHK Sort command is\nof course more useful.\n\n\u003ca name=\"TF_Join\"\u003e\u003c/a\u003e\n\n**TF_Join(Text, StartLine = 1, EndLine = 0, SmartJoin = 0, Char = 0)**\n\n- Purpose: Join lines (section of)\n- Parameters: Text, StartLine, EndLine, SmartJoin, Char\n\n~~~~\nSmartJoin: Detect if CHAR(s) is/are already present at the end of the line before joining the next, this to prevent unnecessary double spaces for example.\nChar: character(s) to use between new lines, defaults to a space. To use nothing use \"\"\n~~~~\n\nNote: StartLine can not use increments. It can have multiple sections.\n\n\u003ca name=\"TF_Save\"\u003e\u003c/a\u003e\n\n**TF_Save(Text, FileName, OverWrite = 1)**\n\n- Purpose: To save a variable to a file\n- Parameters: Text, FileName, OverWrite (O or 1)\n\n~~~~\nOverWrite = 0 create filename_copy.ext if filename.ext exists\nOverWrite = 1 will overwrite filename.ext if filename.ext exists (default)\n~~~~\n\n# TF Lib Errors\n\n1. Error when using the ! prefix.  \n   The correct syntax is \"!file.txt\". If you do this !\"file.txt\" (the ! is not within the quotes it will not be able to read a file)\n2. If you pass on a single zero as text ```TF_TrimLeft(\"0\",1,1,3)``` and there is no file with that name ```\"0\"``` it will shown an error. More as one zero as \"text\" is OK.\n\n# History\n\n**History v3.8, 11 December 2020**\n\n- Prevent TF_Sort from removing last character from the last line https://github.com/hi5/TF/issues/11\n\n**History v3.7, 16 April 2017**\n\n- Added: additional check for passing on just zero/zeros as text to TF functions in TF_GetData() - see v3.6 below\n- Fix: changed readme.md to fix rendering issue of MD files on GH - https://github.com/hi5/TF/issues/5\n\n**History v3.6, 25 December 2014**\n\n- Added: Added additional minor error check in TF_GetData - if \"Text\" is \"false\", there is nothing to process so Exit\n\n**History v3.5, 2 August 2014**\n\n- Changed A_ScriptDir to A_WorkingDir in TF_ReturnOutPut - https://github.com/hi5/TF/issues/1\n- Fixed: TF_ColGet negative startcolumn and sections now work correctly\n\n**History v3.4, 30 October 2010 - UNRELEASED at the time**\n\n- New function: TF_Join: joining lines.\n- Added: A_ThisFunc to helper function TF_MatchList, this may help with error messages such as: Invalid StartLine parameter (non numerical character) - Function used: A_ThisFunc\n- Added/Change: New option for StartLine, Negative startline operate on last X lines was already the case for TF_removelines, applies to all TF functions\n- Added: TF_Substract: Partialmatch = 2 now deletes entire line on partial match, see TF DOC for more info.\n- Added: TF_ColGet and TF_ColPut now accept negative StartColumn parameter. Can be used to Get or Put text in the xth \"column\" from the right, see description above - TF_ColCut does **not** support this as you can use TF_TrimRight.\n- Added: TF_ColGet, TF_ColPut and TF_ColCut can now process multiple columns in one go. Format: CSV or incremental (DO **not** use sections for TF_ColPut due to unexpected end results)\n- Minor improvements to the documentation\n- removed TF_FindLines from lib (was already deprecated)\n\n**History v3.3, 16 April 2010**\n\n- Fixed: If you used variables with any of the replacement functions or tried to remove empty lines from a VARIABLE in the following format: variable:=TF_..(variable,\"search\",\"replace\") and the searchtext was NOT present in the variable it returned an empty variable (e.g. deleted the contents of \"variable\"). It affected TF_ReplaceInLines, TF_Replace, TF_RegExReplaceInLines, TF_RegExReplace, TF_RemoveBlankLines, TF_RangeReplace\\. The built-in check only worked correctly for FILES and with the introduction of variables in TF 3 this didn't surface during testing.\n- Fixed: documentation error for TF_Merge (separator and filename where swapped) and added examples on how to use TF_Merge in a Loop and with FileSelectFile\n\n**History v3.2, 20 February 2010**\n\n- Fixed: TF_AlignRight: due to a bug it didn't work as it should have, it prepended the number of spaces rather than aligning the text at the specified width.\n- Changed: TF_GetData (helper function) should now avoid unnecessary IfNotExist for files, for scripts with many loops in combination with variables it should improve the speed slightly\n- Changed: TF_SplitFileByLines: New options for SplitAt, now three methods available, see notes at function description\n- Changed: TF_RemoveLines: New option for StartLine, if negative value is used it will remove the last X lines from file, see notes at function description\n\n**History v3.1, 09 December 2009**\n\n- Changed: Rewrite of TF_Find. Can now return multiple lines (like TF_Findlines used to), not only linenumbers but the entire line (text) of found lines so it can be used as a basic grep. Now uses RegExp, see compatibility notes.\n- Deprecated: TF_FindLines (see change TF_Find). Kept in for backwards compatibility\n- Updated and expanded documentation with examples and a hopefully \"better\" introduction highlighting some basic concepts\n\n**History v3.0, 27 November 2009**\n\nComplete overhaul of library, now accepts files \u0026 variables for input and output:\n\n- Changed: New parameter for TF_Readlines \u0026 TF_Tail: trailing new line now optional\n- Added: TF_Save, shorthand for filedelete+fileappend\n- Added: TF_GetData, helper function to determine if a file or a variable is passed on to function\n- Added: TF() To read a text file in global var, t by default - Credits various ...\n- Added: TF_ReturnOutput has replaced: Overwrite, MakeCopy and the newly developed ReturnStr\n- Changed: Complete rewrite of TF_Tail, new options - borrowed bits from Tuncay (Thanks!)\n- Changed: MakeMatchList: Removed TF_Countlines (one less fileread), Pass on \"String\" and not a TextFile\n- Fix: TF_ConCat \u0026 TF_MakeFile didn't write output file - same bug as splitby* earlier.\n\n**History v2.5 fix, 01 November 2009**\n\n- Unreleased, but available on request :-) Note that in 2.4a TF_MakeFile and TF_ConCat do not produce output files, easy to fix if you are determined to use an older version of TF.\n\n**History v2.4a fix, 10 August 2009:**\n\n- The fix for TF_SplitFileBy* functions of 2.3b wasn't complete, now  it should work correctly (it didn't write the last file)\n\n**History v2.4 update, 06 August 2009:**\n\n- Added: TF_Sort\n\n**History v2.3b update, 03 August 2009:**\n\n- Fixed: No output problem for TF_SplitFileBy* functions, \"bug\" introduced by 2.3a \"Built in Check if TextFile actually exists\"\n- TF_RemoveBlankLines check if file has empty empty lines to start with, if not return and do nothing (does not create file_copy identical to file)\n- TF_RangeReplace same fix as 2.3a\n\n**History v2.3a update/bugfix (29 July 2009, HugoV, ribbet.1, Murp|e)**\n\nFixed/Changed:\n\n- New features in TF_LineNumber: Restart + Choice of leading/padding character. Thanks for the idea ribbet.1, [http://www.autohotkey.com/forum/viewtopic.php?p=284687#284687](http://www.autohotkey.com/forum/viewtopic.php?p=284687#284687)\n- Built in Check if TextFile actually exists, to prevent creation of empty file(s). Thanks for the idea Murp|e, [http://www.autohotkey.com/forum/viewtopic.php?p=284649#284649](http://www.autohotkey.com/forum/viewtopic.php?p=284687#284687)\n- TF_Replace: if SearchText wasn't present in TextFile the function never returned (stuck in endless loop)\n- TF_ReplaceInLines: if SearchText wasn't present in TextFile simple return an do nothing (faster, does not create file_copy)\n- TF_RegExReplaceInLines: if NeedleRegEx wasn't present in TextFile simple return an do nothing (faster, does not create file_copy)\n\n**History v2.3 (28 July 2009)**\n\n- Added: TF_Tab2Spaces - Note: Thanks to infogulch\n- Added: TF_Spaces2Tab - ditto\n- Added: TF_RangeReplace\n- Added: TF_MakeFile\n\nAlso thanks to Murp|e for pointing out some errors in the documentation (TF_COL\\* functions).\n\n**History v2.2 (10 July 2009)**\n\n- Added: TF_Substract\n- Added: TF_WhiteSpace\n- Added: TF_Wrap\n\n**History v2.1**\n\n- Added: TF_Prepend\n- Added: TF_Append\n\n**History v2.0 (Overhaul by HugoV using TXT lib as starting point)**\n\n- Renamed: TF_TotalLines to TF_CountLines (seemed more logical)\n- Removed: TF_GetCSV, TF_SetCSV to keep the focus on TXT files, CSV requires a different library IMHO (HugoV)\n- Introduced: _MakeMatchList_ and adjusted TF_ReadLines, TF_RemoveLines, TF_InsertPrefix, TF_InsertSuffix, TF_TrimLeft, TF_TrimRight, TF_ColGet, TF_ColPut, TF_ColCut accordingly (HugoV)\n     - Make a MatchList which is used in various functions (listed above)\n     - Using a MatchList gives greater flexibility so you can process multiple sections of lines in one go avoiding repetitive fileread/append actions\n     - You can pass on multiple lines (sections) If you quote the StartLine parameter. Examples of StartLine, Endline:\n     5 ; start from line 5 to the end (StartLine)\n     5, 15 ; lines 5 to 15 (StartLine, EndLine)\n     \"5,13,45,67\", 135) ; lines 5,13,45,67, ignore 135 (\"StartLine\", Endline - EndLine value is ignored)\n     \"5-13,45-51\", 135) ; lines 5 to 13, 45 to 51 ignore 135 (\"StartLine\", Endline - EndLine value is ignored)\n     - Incremental processing of lines, example startline, endline - endline will not be ignored\n     \"2+3\", 150 ; start with line 2, increment 3 up-to line 150 so 2,5,8,11,14 etc\n     \"5+15\" ; start with line 5, increment 15 until end of file so  5,20,35 etc\n- Introduced: _OverWrite_ \u0026 _MakeCopy_ (Heresy / HugoV)\n     - No longer necessary to pass on full path, e.g. \"file.txt\" works OK now (HugoV)\n     - Reduces size of library by removing repeating code sections for saving Output (Heresy)\n     - Backup files: If a subdirectory \"backup\" is present in the directory of TextFile a backup is made before overwriting the original file (both for file.txt and file_copy.txt) with the BAK extension (HugoV)\n     - Includes fix to remove trailing \\`n added by most functions (HugoV)\n- Introduced: SetWidth/space by SKAN for TF_Align* Functions http://www.autohotkey.com/forum/viewtopic.php?p=45880#45880\n- Added: TF_ReplaceInLines. Similar to TF_Replace\n- Added: TF_RegExReplaceInLines. Similar to TF_RegExReplace\n- Added: TF_SplitFileByLines (HugoV)\n- Added: TF_SplitFileByText (HugoV)\n- Added: TF_Merge (HugoV)\n- Added: TF_Find (HugoV, based on example by olegbl)\n- Added: TF_FindLines (HugoV, based on example by olegbl)\n- Change: TF_TrimLeft. 1 - it now processes all lines of the TextFile. 2 - you can now omit EndLine e.g. will process until end of file (HugoV)\n- Change: TF_TrimRight. 1 - it now processes all lines of the TextFile. 2 - you can now omit EndLine e.g. will process until end of file (HugoV)\n- Change: TF_AlignCenter, TF_AlignLeft, TF_AlignRight. Now use SetWidth/space by SKAN, more reliable also adds spaces to RIGHT side of line\n- Change: TF_AlignLeft. 1 - you can now use StartLine, EndLine parameters. 2 - StartLine and/or EndLine can be omitted (HugoV)\n- Change: TF_AlignRight. 1 - you can now use StartLine, EndLine parameters. 2 - StartLine and/or EndLine can be omitted (HugoV)\n- Change: TF_ReadLines you can now omit EndLine e.g. will read until end of file (HugoV)\n- Change: TF_RemoveBlankLines you can now use StartLine, EndLine parameters. EndLine can be omitted (HugoV)\n- Change: TF_InsertLine modified to accommodate line sections and incremental lines.\n- Change: TF_ReplaceLine modified to accommodate line sections and incremental lines.\n- Change: TF_RegExReplace no longer returns \"Counts\" (HugoV)\n- Change: TF_RemoveDuplicateLines 1 - no longer returns \"Removed\". 2 - can use start/end line, 3 - no longer uses sort but keeps original order intact, 4 - to methods to check consecutive lines or unique files in file (HugoV)\n- Change: TF_ColGet, TF_ColPut, TF_ColCut. 1 - order of parameters changed, 2 - now accept Startline, EndLine parameters. (HugoV)\n- Fixed: TF_RemoveDuplicateLines always produced empty Output file (HugoV)\n\n**History prior 2.0 - TXT library (Heresy, HugoV)**\n\n- 2008-06-18 : added TF_AlignLeft(), TF_AlignCenter(),  TF_AlignRight() (Heresy)\n- 2008-06-18 : added TF_Tail(), TF_ReverseLines() (HugoV)\n- 2008-06-17 : added TF_GetCSV(), TF_SetCSV() (Heresy)\n- 2008-06-17 : added TF_LineNumber(), TF_Concat(), TF_ColGet(), TF_ColPut(), TF_ColCut() (HugoV)\n- 2008-06-16 : added TF_RegExReplace(), TF_RemoveLines(), TF_TrimLeft(), TF_TrimRight() (Heresy)\n- 2008-06-15 : added TF_TotalLines(), TF_ReadLines(), TF_RemoveDuplicateLines() (Heresy)\n\n## Credits\n\nThis library is based on the *Library for Text file manipulation* started by [Heresy](http://www.autohotkey.com/forum/profile.php?mode=viewprofile\u0026u=8193). I have contributed a number of functions to that library, but that version also has some \"bugs\" which are hopefully resolved in this TF library.\n\nThanks to:\nHeresy, SKAN! (countlines, setwidth, spaces), Olegbl, (suggestion for find*), infogulch (suggestion for tab \\\u003c-\\\u003e spaces),\nMurp|e (suggestions for documentation, check if file exists), ribbet.1 (New features in TF_LineNumber), Tuncay (help with\nTF() and borrowed ideas for TAIL).\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Text manipulation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi5%2FTF","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhi5%2FTF","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi5%2FTF/lists"}