The thread with no title idea
-
So, I have two questions, I deal with a ton of repeated lines that also have repeating contents on just one line(which I will explain later
However, doing this manually is a really time-consuming task, and I wanted to faster ways of dealing with these, and that’s what these questions are for1# I want to do something like this to be more blunt, as sometimes, I have to deal with like, 200 of these, which consumes alot of time by just Ctrl C + Ctrl Ving everything, which already makes me spend ALOT of time since I have to do it for the content I wanna repeat.
2# A way to replace the first 8 words of multiple lines with a specific text. If you see on [this](https://i.imgur.com/YDo9Pef.png image, I replace the first 8 words that first line with 8 ceros because it’s necessary, however, I have to do this for many others, and this is also a very time-consuming task. It would be also useful for setting the path(which was highlighted in the previous image) for multiple lines too.
Thank whoever is able to help me, as I wasn’t able to find a solution online.
-
Problem 1: I think I get the first image, you just want to duplicate certain character strings. I’m not sure on what the second image is meant to portray, I’ll need more information. Perhaps describe as a before and after style. Like I have
this
text and I’d like to finish withthat
text, then also add in where the text might be found. Is it only on the first line of a file, or could it be anywhere. Will it only be at the start of a line, or anywhere within 1 line.Start with (example for my regex):
abc
123
,.;
\R$
[}{
()+After running the regex get:
abc abc
123 123
,.; ,.;
\R$ \R$
[}{ [}{
()+ ()+Find:
((?|abc|123|,.;|\\R\$|\[\}\{|\(\)\+))
Replace:\1 \1
note a space between the 2 ‘\1’.To run this regex you need to have the Replace option set with ‘Wrap around’ and ‘Regular expression’ selected (ticked). Insert the expression as shown above and click on the replace all button. I would suggest you may want to start small first, maybe just try to look for 2 or 3 of the strings you want. Make a backup of the file before replacing anything. You should then verify that what you wanted actually occurred. Problems can occur through lots of reasons, mistyping the regex (copying and pasting is generally best), a misunderstanding of the problem and also under what circumstances the replacements are supposed to work or not (if exclusions are required).
Note that I’ve included some other strings and the reason is that these characters are special characters. They have special meaning within regular expressions (regex’s). To make them be literally the character rather than the special meaning we have to use an escape character, which is the
\
. So looking for\R$
we have to ‘escape’ 2 of these characters, the\
and the$
. In the next 2 options in my example we have to ‘escape’ all 3 characters in each one as the[]{} and ()
are special characters as well. There are others so you will need to read up on the complete list, https://www.regular-expressions.info/characters.html has a good listing. Until you know which characters are likely to be special characters you won’t know if your version of my regex will succeed or not. I’m assuming here that the strings you want to duplicate will be more than just the example shows.The regex I supplied does not test if there are already duplicated strings, so if you run the regex once, a second run will
AGAIN
duplicate the strings you are searching for.Problem 2: It would appear from your name and the words you use that English isn’t your primary language. I say that as you say ‘replace the first 8 words that first line with 8 ceros’. I think you mean 8 zeros (the number 0) as I see that at the start of the highlighted line. Each letter (or number) is called a character, not a word. What I’m writing in this sentence are a bunch of words. Before I can help further I’d also need more information (description) of this problem, same as #1. A before and after description with perhaps more examples.
Terry
-
I don’t know, Deputy…I think this short one meets the original spec for the first problem:
Find what zone:
(?-s)^.+
Replace with zone:$0 $0
Search mode: Regular expression:-D
-
Yes sure would Scott (I welcome your feedback, remember I’m the newbie!)…
I was in a dilemma as it appeared the example was very unlikely to be ‘real life data’, rather just a representative of it. Your answer will in effect duplicate any length of characters on 1 line. I gathered that character strings of 3 seemed to be one of the concepts put forward, however the strings were in most cases just consecutive characters, not what anyone could believe likely to be real.
My answer though (in all honesty) probably contained too much information. Helping people isn’t all that easy is it? It’s a fine line between supplying just what was requested or trying to explain a few more things in the belief that there was something else not covered in the example, sort of guidance.
So the saying:
Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.
comes to mind.Terry
-
I tend to give 'em what they ask for, let them refine it once when they realize they’ve screwed it up, then lose interest like an airplane losing altitude when they keep changing it infinitely and think I’m going to provide an equal amount of free consulting work (which is what it is). Trying to read their minds is a losing proposition. If they provide sample data, they’d better make it representative. Otherwise I point them to some regex docs and wish them well. This ISN’T a regex site, after all…