Getdata from specific positions (only if position x is not "0") and replace another positions with it



  • HI all, i’m kinda newbie at using notepad++, finding it’s awesome uses and functions…
    I’m trying to edit some files, here’s what i need to accomplish:
    I need to copy the info from positions 117 to 121 (5 numbers, fixed position, thousands of lines) and replace the info on position 120 to 124 with the info i got from 117 to 121 (replacing 117 to 119 with zeroes), but i only would do that on lines that the caracter on position 119 is diferent from 0, otherwise no need need to be done on that line.
    here’s a example of a line that would need to changed (2 on 119° position. I assume site would change format of line so it won’t show as in the archive, but it’s the first 126 caracteres -from a 400 fixed position line, i believe should be enough to explain my need)
    1 A000RY029052 162006335 232601170024104001
    -so the line would turn into this (the line should stay with 400 positions):
    1 A000RY029052 162006335 232601170000024101
    -and here’s a example of a line that shouldn’t be affected by (had 0 on position 119 and should stay as is)
    1 A018AC000002 172017097 122601170000064401

    Any help is greatly appreciated, as i’m not getting luck in figuring it out until now.
    (As a plus, if there’s a way to execute this function leaving the first and last line out, that would be excelent).

    Thx a lot in advance for any help.



  • @Denis-Sta

    Not too hard; I’ll leave the bonus part to someone else, though. :-D

    Find-what box: ^(.{116})(..[^0]..).{3}
    Replace-with box: \1000\2
    Search mode: Regular expression

    How it works:

    Starting at the beginning of each line, remember 116 characters as group-1, then remember the next 5 characters where the middle digit (or col 119 digit) is not zero as group-2, then grab the next 3 characters (don’t remember those 3 as they will not be used in the replace part). Now that we have these things remembered, replace the entire matched part of the line (which is the first 124 characters) with the memorized group-1 data, followed by three zeroes, followed by the remembered group-2 data.



  • Great, thx a lot, i was doing something like that, but was missing some key parts, that would solve my problem, thx again.
    Il’l take a look around, maybe i can contribute aswering some other easier questions.
    Regards.



  • btw this worked on multiple archives, without need to filter the lines (as the first and last lines didn’t had any “0” on the 119° position they aren’t changed at all.
    Thx again.



  • I’m glad it was helpful to you.

    In the future for postings that are helpful, instead of posting a “thanks”, simply press the caret-like “UP-vote” button (see picture below) on that posting.

    This:

    • Will let me know that you found value in my posting; effectively a “thanks” (I get a notification)
    • Won’t waste the bandwidth of others that read the Community with a valueless (to them) “thanks” posting they have to read [they won’ t see new things in their “Inbox” for upvotes]
    • Will increase my “reputation”; whatever the value is in that… “repu-coins”? :-D



  • Great, i will do that.
    Another question, how would i add a parameter like “or” on 2nd group?
    like: i want to replace if 119° “or” 120° caracter are diferent from zero or space (i could add the space no problem, but as i add 2 parameters it only would replace when both are valid)…



  • @Contafisc-Empresarial

    Unless I am misunderstanding what you are wanting to do (very possible!), I’d say that changing [^0]. to [^\s0]{2} does what you need. It means: for the next two positions, match as long as both positions are not some combination of:

    • whitespace (the \s)
    • zero (the 0)

Log in to reply