Mass replacement of lines in a text file (Notepad ++)

I am using Notepad ++ to edit a text file with a poorly encoded log. The program did not take into account the AZERTY keyboard layout for the user. The result is a text file as follows (example I did)

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 do bulk character swap as follows

 a > q q > a [/0] > 0 ! > 1 

and several others

Can I create a character table to replace? I'm a little newbie and I don't know if Notepad ++ allows scripts to run

+6
source share
3 answers

Notepad ++ has macro photography, but macros cannot be recorded in any documented embedded language. You can record a macro that performs 70 search and replace operations. See this explanation . There is some information about "hacking" a macro language here .

Obviously, Notepad ++ is not intended for this task. Python solutions are fine, but Perl was originally intended for such things. Here is a single line. This is for Windows. On bash / Linux, replace double quotes with single quotes.

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

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

+1
source

I do not know about Notepad ++. But if you have python installed on your computer, you can get 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 tweak the replace_dict variable to suit your needs.

0
source

So, there are quite a few different AZERTY layouts, so this is not a complete answer. However, it passes your test case and does it as fast as any single character replacement can be done in python (unless you need to accept unicode )

 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, until you find out which version of AZERTY your user is using, you should be fine. Just remember to correctly populate the translation table with the details of the AZERTY implementation.

0
source

Source: https://habr.com/ru/post/951368/


All Articles