6

I am using Notepad++ to edit a text file that has been poorly encoded log. The program didn't take into account the AZERTY keyboard layout of the user. The result is a text file as follows (example I made up)

Hi guysm this is Qqron<
I zonder zhen ze cqn go to the szi;;ing pool together
:y phone nu;ber is !%%)@!#@@#(
Cqll ;e/

I need to make bulk replacement of characters as follows

a > q

q > a

[/0] > 0 

! > 1

and a few others

Is it possible to create a table of characters to be replaced ? I'm a bit of a beginner and I don't know whether Notepad++ allows to run scripts

Abel Pastur
  • 1,905
  • 2
  • 24
  • 31

3 Answers3

1

Notepad++ has a macro recorder, but macros can't be written in any documented embedded language. You could potentially record a macro that does 70 or so search and replace operations. See this explanation. There is some information on "hacking" the macro language here.

Clearly Notepad++ was not meant for this task. The Python solutions are okay, but Perl was meant originally for stuff exactly like this. Here's a one-liner. This is for Windows. In bash/Linux, replace the double quotes with single ones.

perl -n -e "tr/aqAQzwZW;:!@#$%^&*()m\/</qaQAwzWZmM1234567890:?./;print"

It will do what @kreativitea's solution does (I used his translation strings), reading the standard input and printing to standard output.

Community
  • 1
  • 1
Gene
  • 46,253
  • 4
  • 58
  • 96
0

I don't know about Notepad++. But if you have python installed in your machine, you can you this little script.

source = """Hi guysm this is Qqron<                                           
I zonder zhen ze cqn go to the szi;;ing pool together                         
:y phone nu;ber is !%%)@!#@@#(                                                
Cqll ;e/"""                                                                   

replace_dict = {'a': 'q', 'q': 'a', '[/0]': '0', '!': '1'}                    

target = ''                                                                   
for char in source:                                                           
    target_char = replace_dict.get(char)                                      
    if target_char:                                                           
        target += target_char                                                 
    else:                                                                     
        target += char                                                        

print target

Just customize the replace_dict variable to suit your need.

favadi
  • 215
  • 2
  • 13
0

So, there are quite a few different kinds of AZERTY layouts, so this isn't a complete answer. However, it does pass your test case, and does it as fast as any single character replacement can be done in python (unless you need to take unicode into account as well)

from string import maketrans

test = '''Hi guysm this is Qqron<
I zonder zhen ze cqn go to the szi;;ing pool together
:y phone nu;ber is !%%)@!#@@#(
Cqll ;e/'''

# warning: not a full table.  
table = maketrans('aqAQzwZW;:!@#$%^&*()m/<', 'qaQAwzWZmM1234567890:?.')

test.translate(table)

So, as long as you find out what version of AZERTY your user is using, you should be okay. Just make sure to properly fill out the translation table with the details of the AZERTY implementation.

Community
  • 1
  • 1
kreativitea
  • 1,741
  • 12
  • 14