• Sorting by a key with offset and length

    Locked
    4
    0 Votes
    4 Posts
    2k Views
    guy038G

    Hello, @abhay-gokhale, and All,

    The is a safe way to sort with an offset, in Notepad++. The trick is to copy the key sort, in front of each line to be sorted ;-))

    Let’s start with that sample text ( A long line from the license.txt file, split in several lines )

    The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

    I, simply, inserted a 5 digits number, surrounded by a space character, at column 11 of each line, giving the following text :

    The licens 37529 es for most software are designed to take away your freedom to share and change 12345 it. By contrast, the GNU General Public License is intended to guarantee 94113 your freedom to share and change free software--to make sure the software i 88060 s free for all its users. This General Public License applies to most of th 46931 e Free Software Foundation's software and to any other program whose authors co 88060 mmit to using it. (Some other Free Software Foundation software is covered by 88060 the GNU Library General Public License instead.) You can apply it to your pr 62473 ograms, too.

    That five digits number will be the expected key sort. Now, applying the regex S/R :

    SEARCH (?-s)^.{11}(.{5}).+

    REPLACE \1\x20\x20\x20$0

    you should get the text :

    37529 The licens 37529 es for most software are designed to take away your freedom to share 12345 and change 12345 it. By contrast, the GNU General Public License is intended to 94113 guarantee 94113 your freedom to share and change free software--to make sure the 88060 software i 88060 s free for all its users. This General Public License applies to 46931 most of th 46931 e Free Software Foundation's software and to any other program whose 88060 authors co 88060 mmit to using it. (Some other Free Software Foundation software is 88060 covered by 88060 the GNU Library General Public License instead.) You can apply it 62473 to your pr 62473 ograms, too.

    Then, after running the sort operation ( Edit > Line Operations > Sort Lines Lexicographically Ascending, you get :

    12345 and change 12345 it. By contrast, the GNU General Public License is intended to 37529 The licens 37529 es for most software are designed to take away your freedom to share 46931 most of th 46931 e Free Software Foundation's software and to any other program whose 62473 to your pr 62473 ograms, too. 88060 authors co 88060 mmit to using it. (Some other Free Software Foundation software is 88060 covered by 88060 the GNU Library General Public License instead.) You can apply it 88060 software i 88060 s free for all its users. This General Public License applies to 94113 guarantee 94113 your freedom to share and change free software--to make sure the

    Notice that, when the key sort is identical ( case of 88060 ), for several lines, the lines are, in addition, sorted, according to the entire line contents ! ( authors - covered - software )

    Finally, using this second simple regex S/R, below, we get rid of the temporary key sort, at column 1 :

    SEARCH (?-s)^.{5}\h+

    REPLACE Leave EMPTY

    and obtain our expected text :

    and change 12345 it. By contrast, the GNU General Public License is intended to The licens 37529 es for most software are designed to take away your freedom to share most of th 46931 e Free Software Foundation's software and to any other program whose to your pr 62473 ograms, too. authors co 88060 mmit to using it. (Some other Free Software Foundation software is covered by 88060 the GNU Library General Public License instead.) You can apply it software i 88060 s free for all its users. This General Public License applies to guarantee 94113 your freedom to share and change free software--to make sure the

    Et voilà !

    Best Regards,

    guy038

  • 1 Votes
    4 Posts
    4k Views
    guy038G

    Hello, @arpad-zsok, @scott-sumner and All,

    Noticing that Arpad’s text contains, only, one | character per row, I suppose that this simple regex S/R, below, would be enough !

    SEARCH [^"]+\|

    REPLACE Leave EMPTY

    But my solution isn’t the true goal of this post, indeed ! While running the Scott’s search regex, below :

    (?-i)^((?:".+?",){11}")[0-9.]+?\|(?=NEGATIVE|POSITIVE)

    against the text :

    "processingIdentifier","dateTime","header/instrumentName","patientIdentifier","lastName","birthdate","sex","location","specimenIdentifier","testIdentifier","dilution","testName","result/value","unit","abnormalFlags","resultStatus","operatorName","resultDateTime","result","simple/resultCode" "A","B","C","D","E","20180328171007","VIDASPC01","F838-843","F838-843","SPT","UP Salmonella","0.07|NEGATIVE","F","20180328115445", "A","B","C","D","E","20180328171008","VIDASPC01","F838-844","F838-844","SPT","UP Salmonella","0.25|POSITIVE","F","20180328115446", "A","B","C","D","E","20180328171007","VIDASPC01","F838-843","F838-843","SPT","UP Salmonella","0.07|NEGATIVE","F","20180328115445",

    I noticed that it took some time ( ~2s ), before finding the first expected zone :

    “A”,“B”,“C”,“D”,“E”,“20180328171007”,“VIDASPC01”,“F838-843”,“F838-843”,“SPT”,“UP Salmonella”,"0.07|

    And I tried to understand that behavior ! First, I realized that the matching delay was due to the headers line, which does not contain any | symbol. Thus, the problem could be simplified !

    In a new tab, let’s build an unique line, with 3 initial “headers” lines, joined together, surrounded with two simple sentences :

    This is a test "ProcessingIdentifier","dateTime","header/instrumentName","patientIdentifier","lastName","birthdate","sex","location","specimenIdentifier","testIdentifier","dilution","testName","result/value","unit","abnormalFlags","resultStatus","operatorName","resultDateTime","result","simple/resultCode","processingIdentifier","dateTime","header/instrumentName","patientIdentifier","lastName","birthdate","sex","location","specimenIdentifier","testIdentifier","dilution","testName","result/value","unit","abnormalFlags","resultStatus","operatorName","resultDateTime","result","simple/resultCode","ProcessingIdentifier","dateTime","header/instrumentName","patientIdentifier","lastName","birthdate","sex","location","specimenIdentifier","testIdentifier","dilution","testName","result/value","unit","abnormalFlags","resultStatus","operatorName","resultDateTime","result","simple/resultCode" This is a text

    and let"s consider the generic regex ^(?-is)(".+?",){N}"z, where the letter N is any number > 0.Of course, as this text does not contain any lowercase letter z, the regex engine always answers Find: Can’t find the text…". On my old laptop, I obtained, depending of the used regex, the following times, for unmatching :

    With regex ^(?-is)(".+?",){1}"z => Immediate answer

    With regex ^(?-is)(".+?",){2}"z => Immediate answer

    With regex ^(?-is)(".+?",){3}"z => 1s

    With regex ^(?-is)(".+?",){4}"z => 2s

    With regex ^(?-is)(".+?",){5}"z => 7s , with a wrong unique match ( all the file contents !)

    Why the time, for the regex engine, to realize, that there is NO match, becomes exponential ? Well, this comes from the regex part ".+?". Indeed, to understand the process, let’s use the regex ^(?-is)(".+?",){1}"z, which can, also, be written ^(?-is)".+?","z

    Actually, due to the lazy quantifier +?, this regex means : Find the smallest range of standard characters, between two " symbols, which is followed with the string ,"z !

    So, let’s add a z lowercase letter, at the beginning of the second column header, as below :

    "ProcessingIdentifier","zdateTime","header/instrumentName","patientIdentifier","lastName","birthdate",......

    The regex part ".+?" catches the string “ProcessingIdentifier” and the part ,"z matches the ,"z string

    Now, let’s add, instead, a z lowercase letter, at the beginning of the third column header, as below :

    "ProcessingIdentifier","dateTime","zheader/instrumentName","patientIdentifier","lastName","birthdate",......

    This time, the regex part ".+?" catches the string “ProcessingIdentifier”,“dateTime” and the part ,"z matches the ,"z string

    And so on…, till inserting a z character at beginning of the last header :

    "ProcessingIdentifier","dateTime","header/instrumentName",...................,"resultDateTime","result","zsimple/resultCode"

    This time, the regex part ".+?" catches the huge string “ProcessingIdentifier”,“dateTime”…“resultStatus”,“operatorName”,“resultDateTime”,“result” ( 855 chars ) and the part ,"z matches the ,"z string, before the last header of the text ( simple/resultCode )

    So , depending of the location of that z letter, the quantifier +? takes as many non-null characters as to meet the ,"z string ! This regex engine behavior can be considered as a foretracking operation ( by analogy to the backtracking one ! )

    Now, everyone can understand why, if no z letter exists in the text, the time to answer becomes exponential, when replacing the {1} quantifier with greater values and, even with the {5} quantifier, I, personally, got a catastrophic foretracking :-((

    Don’t forget that, for instance, the regex ^(?-is)(".+?",){11}"z can be rewritten :

    ^(?-is)".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?","z

    And, as any part ".+?" may concern any form "....", "....","....", "....","....","....",…, it’s not difficult to guess that, because of the multiple possible combinations, troubles are not very far :-((

    Two obvious solutions to that problem are to use the regexes ^(?-is)("[^,]+?",){11}"z or ^(?-is)("[^"]+?",){11}"z

    However, I, also, got an other strange solution : to use the regex ^(?-is)(".+?",){11}+"z, with the possessive quantifier {11}+. Indeed, when no z letter exists in the list of headers, the negative answer, of the regex engine, is immediate !

    At first sight, this {11}+ syntax seems quite weird, because the {11} quantifier cannot change and the backtracking/foretracking process does not seem to be involved with that quantifier ! But, actually, this means that the regex engine, will not try any combination, after a first unmatched search, in the regex part ".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",".+?",

    And, if your add a z, at beginning of the 12th header ( “ztestName” ), you 'll get , with the regex ^(?-is)(".+?",){11}+"z, the only possible match :-))

    In conclusion, the initial Scott’s regex should be used, with one the three syntaxes, below :

    (?-i)^((?:"[^,]+?",){11}")[0-9.]+?\|(?=NEGATIVE|POSITIVE)

    (?-i)^((?:"[^"]+?",){11}")[0-9.]+?\|(?=NEGATIVE|POSITIVE)

    (?-i)^((?:".+?",){11}+")[0-9.]+?\|(?=NEGATIVE|POSITIVE)

    Cheers,

    guy038

  • UDL bug about 'Comment line style'

    Locked
    1
    0 Votes
    1 Posts
    692 Views
    No one has replied
  • Keep session when launching NPP but files don't exsit

    Locked
    1
    0 Votes
    1 Posts
    619 Views
    No one has replied
  • -1 Votes
    1 Posts
    638 Views
    No one has replied
  • Wanting to Format 2000000 Lines of Text

    14
    0 Votes
    14 Posts
    4k Views
    Mark AllenM

    Mate

    Thank you so so so Much for your help with this, I truly mean that, it worked perfectly, If its okay, I am going to distribute this way to the supplier of the product so we can use it to make better reports from this program!!!

    Truly Thank you heaps, and thanks for Explaination as well, I should be able to use this in the future to write up my own rules…

    Again thanks heaps!!!

    Mark

  • Macros not in either shortcuts.xml file.

    3
    0 Votes
    3 Posts
    3k Views
    Steve PohorskyS

    One of my mottos is “Computers are less frustrating when we face them together.” One of the best ways historically of figuring things out like this is to grab someone else and show them what you are doing, and get their opinion. Of course, this forum is supposed to serve the same function, but the forum only knows the few details you share.
    When I looked at my shortcuts.xml file, I closed Notepad++ and used the regular Notepad to look at the xml file. Please try this if you have not already done so.
    Otherwise, please be patient to do the standard things:

    Do a full restart of your computer. Upgrade to the newest version of Notepad++. Post again, giving the version of your OS.
    Steve
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • Don't autocomplete on space!

    Locked
    1
    0 Votes
    1 Posts
    636 Views
    No one has replied
  • How to make colored font for .tpl file like .php or .html?

    Locked
    1
    0 Votes
    1 Posts
    832 Views
    No one has replied
  • Removing Spaces after aligning text in columns

    Locked
    1
    0 Votes
    1 Posts
    733 Views
    No one has replied
  • Recent Instability in Notepad++ 7.5.6

    Locked
    2
    0 Votes
    2 Posts
    977 Views
    chcgC

    I didn’t observe such issues with this version of N++. I’m using a similar configuration except of NppExec. Which version of NppExec do you use? 0.6 beta1?

  • Replaceing using wildcard.

    9
    0 Votes
    9 Posts
    6k Views
    Zoltan MeszarosZ

    Howdy folks,

    Thanks guy038 and 古旮 for the info and reference links. I will be chewing on those for a good while, especially considering that the further I edit this thing, the more I want to automate the process thus the more I need to learn how to use expressions.

    Apologies for the response lag, internet was down for 5 days and when it came back up I was swarmed by emails. Sorry 古旮 also for the confusion, I write as I speak, and don’t always pay attention when I am using slang when composing a message. When I said “Strip the Numbers” I meant “remove that data from the file”.

    Folks, thank you all so very much for the guidance, examples, and references. I have a feeling I will be seeing this site again and again. Here’s hoping that Expressions are easier to teach myself than scripting. Peace out to y’all.

    -Z-

  • CTRL+F the "Find" window

    Locked
    5
    0 Votes
    5 Posts
    3k Views
    redorbroderR

    I often think when it comes to computers and software, that if I come across a problem or in this case a “design behavior” as you call it, I’m not alone. :D
    So I think of keeping the “Find” window open as an improvement and more users than me would find it useful.

    Best regards

  • How to restore the all the setting of notepad++(except reinstalling)

    Locked
    2
    0 Votes
    2 Posts
    7k Views
    ITIVII

    Get the answer,inspired and trying.

    In the newest version, it’s not enough to delete all the .xml files in C:\Users\X\AppData\Roaming\Notepad++.
    You must delete files in C:\Users\X\AppData\Roaming\Notepad++\backup as well.
    Then just restart.

  • Shortcut key for File > Reload from Disk

    Locked
    3
    0 Votes
    3 Posts
    3k Views
    Patrick CoyneP

    Very useful! Thank you!

  • Notepad++ crashed with NULLs.

    Locked
    2
    0 Votes
    2 Posts
    4k Views
    PeterJonesP

    Unfortunately, you’re not alone. Comptuer crashes can cause unexpected behavior, and so far, no one in the development team has been able to reliably replicate and thus debug how to prevent the problem. This is officially tracked in issue #2381

    Regarding the specifics of your instance: you mentioned checking in %AppData%/Notepad++/plugins/config/NppFTP/Cache… but that’s only used to cache files if you’re using the NppFTP plugin to edit remote files (on your webserver, or similar). The right directory location for Notepad++'s backup (assuming you have Settings > Prefrences > Backup enabled) would be %AppData%\Notepad++\Backup: did you check there? Also, if you used a “local”/portable version (check ? menu > Debug Info, and look for “Local Conf mode:”; if it says ON, then it’s “local”), then the backup directory would be a subdirectory of your whatever directory notepad++.exe is in, rather than in the %AppData% hierarchy.

    Unfortunately, if it’s not there, there’s probably not much we can do to help you recover it. However, you’re luckier than some, if your statement that “whatever data I had saved till yesterday is also fine” means that you did have your own backup somewhere, and that you’ve just lost the most recent edits. (If not, for the future, I highly recommend that you keep a backup of any important data**. This can be done with dedicated backup software, or with storing your files in a service like dropbox or one drive or google drive or similar. Or using version control software, such as git or subversion.)

    History:

    Back in December 2017, @chcg summarized the history of the topic up to that point: https://notepad-plus-plus.org/community/topic/14945/rare-null-write-glitch/2, which @Scott-Sumner updated in January (https://notepad-plus-plus.org/community/topic/15112/attempt-to-recover-files-after-npp-blank-2-files-after-error-missed-the-error-msg/2)

    Since then, there have been at least a few more posts on the issue in this forum (incomplete):

    https://notepad-plus-plus.org/community/topic/15549/help-my-pc-crashed-while-editing-and-deleted-my-whole-document/2 https://notepad-plus-plus.org/community/topic/15531/nul-nul-nul-problem-notpad

    In March, I posted (https://notepad-plus-plus.org/community/topic/13302/fix-corrupted-txt-file-null/19) that I’d tried to force Windows to crash, but no matter what I did, I could not replicate the NUL-file issue. And @Scott-Sumner had tried the same thing some time earlier, as he revealed in the next post, with the same could-not-repeat-it results). This is a difficult issue to debug, and until someone steps forward with a reliable method of repeating it, it’s probably not going to get fixed.

  • Ensure named files saved on exit

    5
    0 Votes
    5 Posts
    2k Views
    Scott SumnerS

    @Greg-Smith

    Well, here’s the way I have mine set, and I get:

    session restore (to pick up with the files I was working with last time) prompted upon exiting to save any red tabs (unsaved files)

    Imgur

  • Previous installation not detected?

    Locked
    1
    0 Votes
    1 Posts
    785 Views
    No one has replied
  • removing whitespace between columns in a .txt data file

    Locked
    8
    0 Votes
    8 Posts
    14k Views
    Too GladT

    @Herb-Martin

    Many thanks Herb-Martin for your suggestion. Much appreciated.