Sign in to follow this  
Followers 0
antisocialneedinghelp

Any way to scan a textfile and delete everything after the first : in each line?

5 posts in this topic

Woohoo! Back again for more assistance!

So. Does anyone know a way this is possible?

Basically. I will have a textfile that will be....

ejkhfjkhf:jkhdkjhdkjhdedi77d38g239dg9g9

jefdhwejkhfwef8h:wejifhwejhwef

wehdfwejh:ewfg287gf8723gf

323rRfef3:f39f78g39fg93f:Lfui23hf2L23fu2hfui2f:32fih

234df1ds:du19hd912398dh8dh

And I wish to have an app that will read all of the text in each line, then remove EVERYTHING after the first : it comes across in it.

Making the output, look like this.

ejkhfjkhf:

jefdhwejkhfwef8h:

wehdfwejh:

323rRfef3:

234df1ds:

Even if there are multiple :`s in the line of text, I just want it to leave everything before the very first marker.

Anyone have a clue? <3 You have all been so helpful thus far~ It would be very lovely. Might even want to take this to a textbox input for "Keyword to split text?" and just put a : in it, or other trigger word.

However that is not necessary, and can come later to be played with <3 For now. This is all I would need to finish my script.

Share this post


Link to post
Share on other sites



antisocialneedinghelp,

- Read the file into an array with _FileReadToArray.

- Loop through the file using StringInStr to get the position of the first ":".

- Use StringMid or StringLeft to get the charracters to the left of that point and reassign them to the array element.

- Finally use _FileWriteToArray to rewrite the file. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Try this one-liner:

FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1"))
1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Other examples, with and without colons:-

If FileExists("in.txt") = 0 Then FileWrite("in.txt", _
        "ejkhfjkhf:jkhdkjhdkjhdedi77d38g239dg9g9" & @CRLF & _
        "jefdhwejkhfwef8h:wejifhwejhwef" & @CRLF & _
        "wehdfwejh:ewfg287gf8723gf" & @CRLF & _
        "323rRfef3:f39f78g39fg93f:Lfui23hf2L23fu2hfui2f:32fih" & @CRLF & _
        "234df1ds:du19hd912398dh8dh")

ConsoleWrite("------ jchd without colon.-------" & @LF)
;FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1")) ; jchd without colon.
ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1") & @LF) ; jchd without colon.

ConsoleWrite("------ Results with colon.-------" & @LF)
ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "([^:]*?:).*", "$1") & @LF) ; Results with colon.

ConsoleWrite("------ Results without colon.-----" & @LF)
ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "(:.*)", "") & @LF) ; Without colon, results same as jchd's.

FileDelete("in.txt")

#cs
    ------ jchd without colon.-------
    ejkhfjkhf
    jefdhwejkhfwef8h
    wehdfwejh
    323rRfef3
    234df1ds
    ------ Results with colon.-------
    ejkhfjkhf:
    jefdhwejkhfwef8h:
    wehdfwejh:
    323rRfef3:
    234df1ds:
    ------ Results without colon.-----
    ejkhfjkhf
    jefdhwejkhfwef8h
    wehdfwejh
    323rRfef3
    234df1ds
#ce
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Gosh I love you guys <3 Most helpful support forum I have ever visited, every time I have my answer within a day <3 Love you all, Like`s all around!

Edit:

Erm >< The first script by jchd worked...but it removed linebreaks as well. So I cant identified what is what.

And the second seemed to just delete everything o-o

Ill poke them around abit to see if I can fix them~ But if I dont, Please post a way to <3

Edit:

Fixed

FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(:.*)", @CRLF) & @LF)

thanks the the help folks <3

Edited by antisocialneedinghelp

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0