Sed replace word except when word is preceded by a specific string











up vote
3
down vote

favorite












I want to replace all instance of abc with 123 provided it isn't preceded by https://.



Code:



file=Data.txt
Initial="# Start";
orig="abc";
new="123";

Final="$" # Line Number
sed -r -e "/${Initial}/,${Final}s/${orig}/${new}/g" ${file} # Final doesn't accept $


Data:



# Start

abc.md
https://abc.md
The path is https://abc.md for abc.md
The path for abc.md is https://abc.md


Expected Output:



# Start

123.md
https://abc.md
The path is https://abc.md for 123.md
The path for 123.md is https://abc.md


How can I achieve this?





Note: I also need to use ${Initial} and ${Final} to denote between which the pattern might exist.



This answer doesn't work for the case The path is: https://abc.md abc.md










share|improve this question
























  • Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
    – Kusalananda
    yesterday










  • @Kusalananda No, because the line numbers are nof fixed.
    – Nikhil
    yesterday












  • Is the substitution always happening from the matching of some pattern and to the end of the file?
    – Kusalananda
    yesterday












  • @Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
    – Nikhil
    yesterday















up vote
3
down vote

favorite












I want to replace all instance of abc with 123 provided it isn't preceded by https://.



Code:



file=Data.txt
Initial="# Start";
orig="abc";
new="123";

Final="$" # Line Number
sed -r -e "/${Initial}/,${Final}s/${orig}/${new}/g" ${file} # Final doesn't accept $


Data:



# Start

abc.md
https://abc.md
The path is https://abc.md for abc.md
The path for abc.md is https://abc.md


Expected Output:



# Start

123.md
https://abc.md
The path is https://abc.md for 123.md
The path for 123.md is https://abc.md


How can I achieve this?





Note: I also need to use ${Initial} and ${Final} to denote between which the pattern might exist.



This answer doesn't work for the case The path is: https://abc.md abc.md










share|improve this question
























  • Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
    – Kusalananda
    yesterday










  • @Kusalananda No, because the line numbers are nof fixed.
    – Nikhil
    yesterday












  • Is the substitution always happening from the matching of some pattern and to the end of the file?
    – Kusalananda
    yesterday












  • @Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
    – Nikhil
    yesterday













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I want to replace all instance of abc with 123 provided it isn't preceded by https://.



Code:



file=Data.txt
Initial="# Start";
orig="abc";
new="123";

Final="$" # Line Number
sed -r -e "/${Initial}/,${Final}s/${orig}/${new}/g" ${file} # Final doesn't accept $


Data:



# Start

abc.md
https://abc.md
The path is https://abc.md for abc.md
The path for abc.md is https://abc.md


Expected Output:



# Start

123.md
https://abc.md
The path is https://abc.md for 123.md
The path for 123.md is https://abc.md


How can I achieve this?





Note: I also need to use ${Initial} and ${Final} to denote between which the pattern might exist.



This answer doesn't work for the case The path is: https://abc.md abc.md










share|improve this question















I want to replace all instance of abc with 123 provided it isn't preceded by https://.



Code:



file=Data.txt
Initial="# Start";
orig="abc";
new="123";

Final="$" # Line Number
sed -r -e "/${Initial}/,${Final}s/${orig}/${new}/g" ${file} # Final doesn't accept $


Data:



# Start

abc.md
https://abc.md
The path is https://abc.md for abc.md
The path for abc.md is https://abc.md


Expected Output:



# Start

123.md
https://abc.md
The path is https://abc.md for 123.md
The path for 123.md is https://abc.md


How can I achieve this?





Note: I also need to use ${Initial} and ${Final} to denote between which the pattern might exist.



This answer doesn't work for the case The path is: https://abc.md abc.md







text-processing sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









Nikhil

23819




23819












  • Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
    – Kusalananda
    yesterday










  • @Kusalananda No, because the line numbers are nof fixed.
    – Nikhil
    yesterday












  • Is the substitution always happening from the matching of some pattern and to the end of the file?
    – Kusalananda
    yesterday












  • @Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
    – Nikhil
    yesterday


















  • Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
    – Kusalananda
    yesterday










  • @Kusalananda No, because the line numbers are nof fixed.
    – Nikhil
    yesterday












  • Is the substitution always happening from the matching of some pattern and to the end of the file?
    – Kusalananda
    yesterday












  • @Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
    – Nikhil
    yesterday
















Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
– Kusalananda
yesterday




Would you be happy with a solution that uses line numbers (not regular expressions for addressing the relevant bit of the input)?
– Kusalananda
yesterday












@Kusalananda No, because the line numbers are nof fixed.
– Nikhil
yesterday






@Kusalananda No, because the line numbers are nof fixed.
– Nikhil
yesterday














Is the substitution always happening from the matching of some pattern and to the end of the file?
– Kusalananda
yesterday






Is the substitution always happening from the matching of some pattern and to the end of the file?
– Kusalananda
yesterday














@Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
– Nikhil
yesterday




@Kusalananda Yes the substitution happens between ${Iniital} and to end of the file.
– Nikhil
yesterday










2 Answers
2






active

oldest

votes

















up vote
4
down vote













What you are looking for is negative-look-behind, which neither sed or awk supports. I recommend going with perl, e.g.:



file=Data.txt
export Initial="# Start"
export orig="abc"
export new="123"
export Final="5"

perl -pe '
$flag=1 if /$ENV{Initial}/;
s,(?<!https://)$ENV{orig},$ENV{new},g if $flag;
$flag=0 if $. == $ENV{Final};
' $file





share|improve this answer





















  • Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
    – sudodus
    yesterday












  • @sudodus: It does if it occurs before the Final line, line number 5 in the above example
    – Thor
    yesterday










  • You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
    – sudodus
    yesterday










  • @Thor How to make Final as the last line? In sed we use $.
    – Nikhil
    yesterday






  • 1




    @Nikhil: You can also set Final to 0, which will never be true
    – Thor
    yesterday


















up vote
2
down vote













You could temporarily change all instances that start with https://to something else, not containing abc, and change them back when you've finished.



Lazy method



sed -e 's_https://abc_protected_g;/# Start/,$s_abc_123_g;s_protected_https://abc_'


You'll have to pick some value for the temporary string, that you can be certain won't appear in your input (and doesn't contain any special characters that would interfere with sed or shell quoting). I used protected but something more distinctive is advisable.



Thorough method



If you can't be certain that your temporary string won't occur in the input, a longer but safer alternative would be to use two replacement strings:



sed -e 's/X/Xv/g;s_https://abc_Xu_g;/^# Start/,$s/abc/123/g;s_Xu_https://abc_g;s/Xv/X/g'


The requirements of these two temporary strings are:




  • They have a common prefix (I used X, but it can be longer/more readable)

  • They don't occur within the other variables: orig, new, Initial or Final

  • As before, they don't contain characters that would break the sed expression






share|improve this answer























  • It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
    – Weijun Zhou
    yesterday












  • @WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
    – tripleee
    yesterday












  • There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
    – Weijun Zhou
    23 hours ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487725%2fsed-replace-word-except-when-word-is-preceded-by-a-specific-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













What you are looking for is negative-look-behind, which neither sed or awk supports. I recommend going with perl, e.g.:



file=Data.txt
export Initial="# Start"
export orig="abc"
export new="123"
export Final="5"

perl -pe '
$flag=1 if /$ENV{Initial}/;
s,(?<!https://)$ENV{orig},$ENV{new},g if $flag;
$flag=0 if $. == $ENV{Final};
' $file





share|improve this answer





















  • Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
    – sudodus
    yesterday












  • @sudodus: It does if it occurs before the Final line, line number 5 in the above example
    – Thor
    yesterday










  • You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
    – sudodus
    yesterday










  • @Thor How to make Final as the last line? In sed we use $.
    – Nikhil
    yesterday






  • 1




    @Nikhil: You can also set Final to 0, which will never be true
    – Thor
    yesterday















up vote
4
down vote













What you are looking for is negative-look-behind, which neither sed or awk supports. I recommend going with perl, e.g.:



file=Data.txt
export Initial="# Start"
export orig="abc"
export new="123"
export Final="5"

perl -pe '
$flag=1 if /$ENV{Initial}/;
s,(?<!https://)$ENV{orig},$ENV{new},g if $flag;
$flag=0 if $. == $ENV{Final};
' $file





share|improve this answer





















  • Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
    – sudodus
    yesterday












  • @sudodus: It does if it occurs before the Final line, line number 5 in the above example
    – Thor
    yesterday










  • You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
    – sudodus
    yesterday










  • @Thor How to make Final as the last line? In sed we use $.
    – Nikhil
    yesterday






  • 1




    @Nikhil: You can also set Final to 0, which will never be true
    – Thor
    yesterday













up vote
4
down vote










up vote
4
down vote









What you are looking for is negative-look-behind, which neither sed or awk supports. I recommend going with perl, e.g.:



file=Data.txt
export Initial="# Start"
export orig="abc"
export new="123"
export Final="5"

perl -pe '
$flag=1 if /$ENV{Initial}/;
s,(?<!https://)$ENV{orig},$ENV{new},g if $flag;
$flag=0 if $. == $ENV{Final};
' $file





share|improve this answer












What you are looking for is negative-look-behind, which neither sed or awk supports. I recommend going with perl, e.g.:



file=Data.txt
export Initial="# Start"
export orig="abc"
export new="123"
export Final="5"

perl -pe '
$flag=1 if /$ENV{Initial}/;
s,(?<!https://)$ENV{orig},$ENV{new},g if $flag;
$flag=0 if $. == $ENV{Final};
' $file






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Thor

11.5k13358




11.5k13358












  • Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
    – sudodus
    yesterday












  • @sudodus: It does if it occurs before the Final line, line number 5 in the above example
    – Thor
    yesterday










  • You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
    – sudodus
    yesterday










  • @Thor How to make Final as the last line? In sed we use $.
    – Nikhil
    yesterday






  • 1




    @Nikhil: You can also set Final to 0, which will never be true
    – Thor
    yesterday


















  • Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
    – sudodus
    yesterday












  • @sudodus: It does if it occurs before the Final line, line number 5 in the above example
    – Thor
    yesterday










  • You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
    – sudodus
    yesterday










  • @Thor How to make Final as the last line? In sed we use $.
    – Nikhil
    yesterday






  • 1




    @Nikhil: You can also set Final to 0, which will never be true
    – Thor
    yesterday
















Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
– sudodus
yesterday






Does not work with The path is https://abc.md for abc.md as per the OP's updated requirement. I updated my answer, and I think you can update yours ;-)
– sudodus
yesterday














@sudodus: It does if it occurs before the Final line, line number 5 in the above example
– Thor
yesterday




@sudodus: It does if it occurs before the Final line, line number 5 in the above example
– Thor
yesterday












You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
– sudodus
yesterday




You are right about that. (A bit difficult to see for a perl illiterate, but it works) :-)
– sudodus
yesterday












@Thor How to make Final as the last line? In sed we use $.
– Nikhil
yesterday




@Thor How to make Final as the last line? In sed we use $.
– Nikhil
yesterday




1




1




@Nikhil: You can also set Final to 0, which will never be true
– Thor
yesterday




@Nikhil: You can also set Final to 0, which will never be true
– Thor
yesterday












up vote
2
down vote













You could temporarily change all instances that start with https://to something else, not containing abc, and change them back when you've finished.



Lazy method



sed -e 's_https://abc_protected_g;/# Start/,$s_abc_123_g;s_protected_https://abc_'


You'll have to pick some value for the temporary string, that you can be certain won't appear in your input (and doesn't contain any special characters that would interfere with sed or shell quoting). I used protected but something more distinctive is advisable.



Thorough method



If you can't be certain that your temporary string won't occur in the input, a longer but safer alternative would be to use two replacement strings:



sed -e 's/X/Xv/g;s_https://abc_Xu_g;/^# Start/,$s/abc/123/g;s_Xu_https://abc_g;s/Xv/X/g'


The requirements of these two temporary strings are:




  • They have a common prefix (I used X, but it can be longer/more readable)

  • They don't occur within the other variables: orig, new, Initial or Final

  • As before, they don't contain characters that would break the sed expression






share|improve this answer























  • It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
    – Weijun Zhou
    yesterday












  • @WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
    – tripleee
    yesterday












  • There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
    – Weijun Zhou
    23 hours ago

















up vote
2
down vote













You could temporarily change all instances that start with https://to something else, not containing abc, and change them back when you've finished.



Lazy method



sed -e 's_https://abc_protected_g;/# Start/,$s_abc_123_g;s_protected_https://abc_'


You'll have to pick some value for the temporary string, that you can be certain won't appear in your input (and doesn't contain any special characters that would interfere with sed or shell quoting). I used protected but something more distinctive is advisable.



Thorough method



If you can't be certain that your temporary string won't occur in the input, a longer but safer alternative would be to use two replacement strings:



sed -e 's/X/Xv/g;s_https://abc_Xu_g;/^# Start/,$s/abc/123/g;s_Xu_https://abc_g;s/Xv/X/g'


The requirements of these two temporary strings are:




  • They have a common prefix (I used X, but it can be longer/more readable)

  • They don't occur within the other variables: orig, new, Initial or Final

  • As before, they don't contain characters that would break the sed expression






share|improve this answer























  • It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
    – Weijun Zhou
    yesterday












  • @WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
    – tripleee
    yesterday












  • There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
    – Weijun Zhou
    23 hours ago















up vote
2
down vote










up vote
2
down vote









You could temporarily change all instances that start with https://to something else, not containing abc, and change them back when you've finished.



Lazy method



sed -e 's_https://abc_protected_g;/# Start/,$s_abc_123_g;s_protected_https://abc_'


You'll have to pick some value for the temporary string, that you can be certain won't appear in your input (and doesn't contain any special characters that would interfere with sed or shell quoting). I used protected but something more distinctive is advisable.



Thorough method



If you can't be certain that your temporary string won't occur in the input, a longer but safer alternative would be to use two replacement strings:



sed -e 's/X/Xv/g;s_https://abc_Xu_g;/^# Start/,$s/abc/123/g;s_Xu_https://abc_g;s/Xv/X/g'


The requirements of these two temporary strings are:




  • They have a common prefix (I used X, but it can be longer/more readable)

  • They don't occur within the other variables: orig, new, Initial or Final

  • As before, they don't contain characters that would break the sed expression






share|improve this answer














You could temporarily change all instances that start with https://to something else, not containing abc, and change them back when you've finished.



Lazy method



sed -e 's_https://abc_protected_g;/# Start/,$s_abc_123_g;s_protected_https://abc_'


You'll have to pick some value for the temporary string, that you can be certain won't appear in your input (and doesn't contain any special characters that would interfere with sed or shell quoting). I used protected but something more distinctive is advisable.



Thorough method



If you can't be certain that your temporary string won't occur in the input, a longer but safer alternative would be to use two replacement strings:



sed -e 's/X/Xv/g;s_https://abc_Xu_g;/^# Start/,$s/abc/123/g;s_Xu_https://abc_g;s/Xv/X/g'


The requirements of these two temporary strings are:




  • They have a common prefix (I used X, but it can be longer/more readable)

  • They don't occur within the other variables: orig, new, Initial or Final

  • As before, they don't contain characters that would break the sed expression







share|improve this answer














share|improve this answer



share|improve this answer








edited 19 hours ago

























answered yesterday









JigglyNaga

3,633829




3,633829












  • It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
    – Weijun Zhou
    yesterday












  • @WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
    – tripleee
    yesterday












  • There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
    – Weijun Zhou
    23 hours ago




















  • It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
    – Weijun Zhou
    yesterday












  • @WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
    – tripleee
    yesterday












  • There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
    – Weijun Zhou
    23 hours ago


















It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
– Weijun Zhou
yesterday






It is interesting to see PCRE features implemented in a pure BRE way, in a single sed invocation. I am wondering whether other PCRE features have their equivalents as well.
– Weijun Zhou
yesterday














@WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
– tripleee
yesterday






@WeijunZhou As noted elsewhere this does not reimplement negative lookaheads, only the subproblem of negative lookaheads with a static string. Some Perl / PCRE extensions are purely convenience / syntactic sugar which is straightforward (but often cumbersome or boring) to replace with traditional regex, but e.g. lookarounds genuinely extend the formalism to something which is no longer theoretically equivalent (reducible) to regular expressions.
– tripleee
yesterday














There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
– Weijun Zhou
23 hours ago






There is no contradiction. A PCRE not being reducible to regular expression is one thing, and I agree on that. Using sed to modify the text to assist in pattern matching is another thing, which is no longer simple pattern patching and hence does not contradict. To put it more clearly, there is still no way to use grep to match lookaround patterns with BRE or ERE.
– Weijun Zhou
23 hours ago




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487725%2fsed-replace-word-except-when-word-is-preceded-by-a-specific-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt