add text to even lines
hi everybody, i have a long txt and i need to add some text only to even lines. how to?
i need to have:
Lycan Thrope last edited by Lycan Thrope
Alan Kilborn last edited by
Oooh, that’s not great. :-(
summerwas not in the requirements (much better would have been a requirement – of the solution – to move the caret to top of file before running, and thus the solution could take care of the “even lines” requirement)
\nis not good – if this file has windows line-endings, it isn’t going to work – use
there’s no specification to use regular expression search mode
there’s no specification to make sure that
. matches newlineis unticked (and no usage of a leading
(?-s)on the find expression)
Terry R last edited by Terry R
I would change the
\Ras we don’t know the format of the text file in terms of CR (carriage returns) and/or LF (line feeds) for line endings. This covers both bases.
But; as in most cases; I suspect the example provided isn’t actually a good representation.
When using a regular expression and selecting “Replace All” AND “Wrap around” the expression WILL start at line 1. So a regex that captures 2 lines will do so in the same manner requested. This was explained in a series of posts here provides a link to those.
(?-s)^(.+\R)(.+\R?)will capture line 1 & 2. Then the next iteration will capture 3 & 4 and so on. The
\R?is so the last line which will not have a CR and/or LF will still be captured.
There is another method of determining the even numbered lines which involves some steps including adding numbers to the start of each line, as this would require placing the caret in the first position of the file we guarantee correct line placement. Each number would be repeated, so it shows twice, like 1 1 2 2 3 3 4 4… . Then a regex would remove the first one of the pair. The next regex could then identify the added number which references the “even” numbered line and use that as a key to edit the correct line. Lastly the added numbers could be removed. This is a much more involved process and I think unneeded as the “Replace All” and “Wrap around” option will work as intended.
PS my example regex assumes data on each line
thank you to all for replies
anyway, thank to suggestion by Alan Kilborn, the string by Lycan Thrope work fine with simply replace:
find what: (#summer\R)(.+)
another question: from my long txt file, i have found some different value. sometime i have:
#summer:4, 0000-gold #summer:4, 0001-gold #summer:5.625, 0002-gold #summer:4, 0003-gold #summer:7.2, 0004-gold
and i need to have:
only the first part are the same #summer:
so, i have try with:
but this command does not work. how to?
if this question it’s hard to get, another solution could be to look on my txt all the values that do not correspond to #summer:4, (as in the case of #summer:5.625,)
this would be enough for me
guy038 last edited by guy038
guy, thank you so much for your string. it work like a charm
all the best