I am looking for a way to extract every instance of a string in a certain format from a CSV file. Specifically, I am looking for barcodes, in the format #-#####-#####-#. However, sometimes the barcodes are by themselves and sometimes they are part of a larger string; there's no real pattern to the layout of the CSV file because the person who sends it to me is... frustrating to work with.
I'm guessing what I need is a combination of a file read loop and a RegEx, but A) I'm really bad at RegEx, and B) I don't really know how a file read loop works with a CSV file.
The end goal would be for the script to grab each barcode and append it to a new file on its own line, so that by the end there is a file containing just the barcodes in a vertical column.
Search a CSV File for a Certain String? Topic is solved
Re: Search a CSV File for a Certain String? Topic is solved
Maybe something like this could work for you
Code: Select all
FileRead,File,%A_Desktop%\test.txt
Results:=[],p:=1
while p := RegExMatch(File, "\d-\d+-\d+-\d", Match, p + StrLen(Match)) {
Results.push(Match)
}
for k,v in Results
append.=v "`n"
FileAppend,%append%,%A_Desktop%\test2.txt
Re: Search a CSV File for a Certain String?
First off, WOW that is a clever way of doing a multiline append instead of calling FileAppend repeatedly. ~steals~
That does look like what I need. Specifically the "\d-\d+-\d+-\d" bit I doubt I ever could have figured out on my own. Looks like AHK reads in CSV files more or less just fine, grabbing an entire line at once; I can use a Parse loop to split it from there so that should work. Thanks!
That does look like what I need. Specifically the "\d-\d+-\d+-\d" bit I doubt I ever could have figured out on my own. Looks like AHK reads in CSV files more or less just fine, grabbing an entire line at once; I can use a Parse loop to split it from there so that should work. Thanks!
Who is online
Users browsing this forum: Bing [Bot] and 292 guests