Hi,
I wanted to extract some SHA1 hashes from random text files. So, let's say I have a file like this:
As SHA1 hashes are always 40 character long and use only hexadecimal digits, I can extract then with a simple grep command:
I've been trying to simulate this grep command (in particular the -o option, which makes grep print out only the matching part of the line) with UltraEdit scripting. It takes me a while because I found no easy way to know then the find command went back to the first occurrence found (as UE find is circular), so I don't know when to stop a loop as UltraEdit.activeDocument.isFound() will always return true unless I delete/change the occurrences found, which I don't want to do.
The only way I found is to save the position for the first match and then keep comparing the other ones with it. It's not elegant though. Current working code is like this:
So, is there any easier way to accomplish this? I'm using the latest version of UE on Mac.
Thanks in advance,
Fernando
I wanted to extract some SHA1 hashes from random text files. So, let's say I have a file like this:
Code: Select all
a c0c13ddb9e5ec04ab1561bfaebe4920a6f1bdda9
asklskalk
as dsads fcaa0fed49330b5d07E1c7a300a545cf41ec8df0 8dkds8z
sadadasda
asad 1b866886c46430c871a91ead6e607fad9e291de4 fcaa0fed49330b5d07E1c7a300a545cf41ec8df0
lll
Code: Select all
$ grep -Eo '[[:xdigit:]]{40}' teste.txt
c0c13ddb9e5ec04ab1561bfaebe4920a6f1bdda9
fcaa0fed49330b5d07E1c7a300a545cf41ec8df0
1b866886c46430c871a91ead6e607fad9e291de4
fcaa0fed49330b5d07E1c7a300a545cf41ec8df0
The only way I found is to save the position for the first match and then keep comparing the other ones with it. It's not elegant though. Current working code is like this:
Code: Select all
var doc = UltraEdit.activeDocument;
doc.top();
doc.findReplace.matchWord=true;
doc.findReplace.searchDown=true;
doc.findReplace.regExp=true;
UltraEdit.clearClipboard();
for (i=0, first=0; ; i++) {
doc.findReplace.find("[[:xdigit:]]{40}");
if (! doc.isFound() || first == doc.currentPos)
break;
if (i == 0)
first = doc.currentPos;
else
UltraEdit.clipboardContent += "\n";
doc.copyAppend();
}
UltraEdit.outputWindow.write(i + " occurrences found.");
if (i > 0) {
UltraEdit.newFile();
doc.paste();
}
Thanks in advance,
Fernando