Let's consider the 'file.txt', click for the file contents
I want to substitute the 3rd to the last occurrence of "p".
sed -E 's/(.*)p((.*p){2})/\1@\2/' file.txt
Here, "p" is substituted by "@". I want to know how it works. Can anyone explain me ?