Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to change 1 of the 2 exact same lines in text file using find and replace

    Help wanted · · · – – – · · ·
    2
    4
    54
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Batuhan Hınçal
      Batuhan Hınçal last edited by Batuhan Hınçal

      Hello i have encountered a problem
      i have 2 of these exact couple of lines

      				<!--Team Block-->
      					<div class="col-lg-4 col-md-6 col-sm-12">
                                      ...some unnecessary code...
      				<!--Team Block-->
      					<div class="col-lg-4 col-md-6 col-sm-12">
      

      like this
      but i want to add a class to only the first line using find and replace, unfortunetly it changes the second line like first one but i dont want this to happen (yes i can do that by hand, but i have around 2000 copies of them and my time gap is narrow)
      im sorry my english is really bad and my subject is really confusing .

      PeterJones 1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones @Batuhan Hınçal last edited by

        @Batuhan-Hınçal ,

        Can’t you just click REPLACE once, instead of REPLACE ALL, and it will just find the first instance?
        I guess that won’t work if you’re using the Find in Files dialog.

        • FIND = (?s)\A^(.*?<div class="col-lg-4 col-md-6 col-sm-12)(">)
        • REPLACE = $1 newClass$2
        • REPLACE ALL (or, presumably, REPLACE IN FILES)

        will change

        <!--Team Block-->
        <div class="col-lg-4 col-md-6 col-sm-12">
        ...some unnecessary code...
        <!--Team Block-->
        <div class="col-lg-4 col-md-6 col-sm-12">
        

        to

        <!--Team Block-->
        <div class="col-lg-4 col-md-6 col-sm-12 newClass">
        ...some unnecessary code...
        <!--Team Block-->
        <div class="col-lg-4 col-md-6 col-sm-12">
        

        caveat emptor

        This regex seemed to work for me, based on my understanding of your issue, and is published here to help you learn how to do this. I make no guarantees or warranties as to the functionality for you. You are responsible to save and backup all data before and after running this regex.

        Batuhan Hınçal 2 Replies Last reply Reply Quote 4
        • Batuhan Hınçal
          Batuhan Hınçal @PeterJones last edited by

          @PeterJones Really Thanks for your suggestion i’am really new into notepad++, i’ll try it right now.

          1 Reply Last reply Reply Quote 0
          • Batuhan Hınçal
            Batuhan Hınçal @PeterJones last edited by

            @PeterJones it worked, you’re a big man with big heart you saved me precious hours of my time

            I wish a lot of people help you in your life, god bless you.

            1 Reply Last reply Reply Quote 5
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors