I am using sed -e 's/\(.*\)ABC/\1DEF/' myfile to replace the last occurrence of ABC with DEF in a file.
I want to modify it to replace the last occurrence of ABC with DEF in each line in the file.
Is it possible to do with regex ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to add ‘g’ to the end of your sed:
This tells sed to replace every occurrence of your regex (“globally”) instead of only the first occurrence.
EDIT: You should also add a
$, if you want to ensure that it is replacing the last occurrence of ABC on the line: