Hello. I have a very long txt file that has quite a few pieces of information that I would like to extract and then a bunch of other useless text. The information I would like is always preceded by “file/?qwe=” and is always followed by “”. Can anyone help me with a script that would extract the info I want or remove everything else?
Thank you,
Erik
Model: MBP
Browser: Safari 534.54.16
Operating System: Mac OS X (10.7)
If the file is too big (number of characters) or the list is too long you might get an error, but something like this:
set the_file to choose file
set the_text to read the_file
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"1A"}
try
set text_items to rest of (text items of the_text)
set item_list to {}
repeat with this_item in text_items
set AppleScript's text item delimiters to {"2A"}
set item_list to item_list & first text item of this_item
end repeat
set AppleScript's text item delimiters to tids
on error error_msg
set AppleScript's text item delimiters to tids
display dialog error_msg
return
end try
return item_list
It’s been a while since I’ve written scripts but this seems to work.
You then do with the resulting list whatever.
gl,
Editted:
replace the “A1” and “A2” strings with your delimiters.
Model: MacBook Pro
AppleScript: 2.5
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)