simple question



  • I think what I’m trying to do is so simple it is below the level of this forum and I can’t find it but here goes: I would like to be able to change line 18 of 500+ files from a value of 2 to a value of 4. How can I do this?



  • @davebyers02

    Simple? Not exactly…of course your explanation may have left the door open for some interpretation, but the simplest case is treated below and should get you started at the very least.

    So for this you can use a Regular Expression Replacement at the file-level. Here’s how:

    In the Replace or Find in Files tab of the Find window, set up the following:

    Find-what zone: \A(?-s)((?:.*\R){17})2
    Replace-with zone: ${1}4
    Search mode: Regular expression

    Then you can either press the Replace All in All Opened Documents button if you have all of these files open at once, or you can use the Replace in Files button if you don’t (the latter also requires you to set up the Filters and Directory zones to specify where your files are and what they “look like”).

    How does this work? Let’s break it down:

    To find matches, here’s how:

    \A: only allow matches at start of file
    (?-s): any following . characters to match “any character” are not allowed to match a line-ending character
    (: remember what is inside this until the matching ) occurs – call it capture group #1
    (?: group what occurs between this and the matching ) but don’t remember it as a capture group
    .: match any character
    *: match zero or more of the prior thing (thus match zero or more of any characters)
    \R: match a line ending
    ): close the earlier (?:
    {17}: match the prior thing 17 times (this match the prior 17 lines)
    ): close the earlier )
    2: match a literal 2 character

    To replace matches found, replace complete matches above with:

    ${1}: what was matched in capture group #1 (in this case data from 17 complete lines starting at start of file, plus the 2 leading off line 18)
    4: replace with literal 4 character



  • @davebyers02

    ALSO: It should go without saying but when you are modifying 500+ files in one operation, you should definitely make a backup of the original files before you start experimenting with a new technique!



  • Thank you so much Scott for guiding me here. I have a basic understanding of html and gave up on CSS and that is as far as I have gone with code(newbie alert!) Using exactly what you have provided yields 0 matches but when I back out the search for the 2 value I get hits on all 557 files but it yields lines 1,18,35,and 52. Very interesting and very close I will keep trying different queries.



  • @davebyers02

    Sorry to hear you are having problems. If you remove the literal 2 I can see why you get the results you mention. Really tough to give you any additional pointers unless you provide some sample data…



  • Here is one entire text file pasted into this reply. I am attempting to change line 18 right after Data Method:. All 500+ files are the same format.

    Analyze Date:
    12/03/2017
    Analyze Duration:
    55
    Analyze SUR:
    158
    94
    0
    Analyze ATS:
    21
    20
    0
    Analyze OU:
    21
    28
    1
    Data Method:
    2
    Data Value:
    30
    Comment:

    Date:
    12/3/2017
    Signature:
    F09F912A6ACABCEFD04AC5F0BFAF8515
    Parms:
    0
    11.2502063358248
    0
    0.601766085439315
    9.23891454054654
    0
    6.03692300797431
    0
    0
    10.9813577992515
    8.01276223421337
    0
    0
    0
    1.89662663913352
    2.79439490907931
    2.19726296776875
    2.46595513460703
    8.66885799987796
    0
    0
    0
    16.7990780619981
    0
    0
    0.252143986366326
    3.06192245369595
    0
    6.46145604328437
    1.22309301721895
    3.22405900004174
    4.83321978367822
    2
    1.5
    2
    3
    0
    0
    0
    0
    0
    0
    0
    0
    0
    Situation:
    0
    0
    0
    0
    0
    0



  • @davebyers02

    Well, seeing that’s a relief…I thought I might see some HTML wrapping the 2 on line 18…given your earlier reply where you mentioned HTML. :-)

    So…if I copy and paste your data into a file (or a few) and then run Replace in Files with the earlier expressions I gave, I see the 2 on line 18 changed into a 4…in other words, it seems to work fine for me. I guess I am still missing some important detail about what is making it not work for you. :-(



  • I did get this to work pasting it back in to a new document. The original files have a single space leading each numerical row that get stripped away when pasted into html. I changed the search to include a space in front of the search value and a space in front of the replace value and that seems to work, I will flush it out in more detail tonight. Thanks!


Log in to reply