add characters
-
Hello,
I have a file of 160 000 lines with some empty lines.
I would like to add characters at the beginning of each line, but not when they are empty. I found how to add characters at the beginning or end of the line, but I don’t know the regular expression syntax to go further.
Could someone help me please?Thank you in advance.
-
Hello, @mr-schnok and All,
Not difficult !
SEARCH
(?x) ^ (?! \R )OR^(?!\R)REPLACE
Your text to insert at BEGINNING of NON-EMPTY lines
The search regex means :
Change any beginning of line (
^) with the text to replace, but ONLY IF not immediately followed with aline-breakcharacter, as\Rrepresents, either\r\nor\ror\nBest Regards
guy038
-
Hi, @mr-schnok and All,
Oh… I did not notice that you spoke about adding characters at the end of non-empty lines as well !
In this case, the regex S/R becomes :
SEARCH
(?x-s) (?<= . ) $OR(?-s)(?<=.)$REPLACE
Your text to insert at END of NON-EMPTY lines
The search regex means :
Change any end of line (
$) with the text to insert, but ONLY IF immediately preceded with a standard character (.)BR
guy038
-
Hello @guy038
Thank you very much. It works very well.
And especially thank you for the explanation.Have a nice day.
Phil
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login