How to change 1 of the 2 exact same lines in text file using find and replace
-
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 . -
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.
- FIND =
-
@PeterJones Really Thanks for your suggestion i’am really new into notepad++, i’ll try it right now.
-
@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.