Replace last occurrence of a string
How do you replace instances of a string only in the line where they last occured.for example if you have a file like below:
a b c a dThe output should look like below:
a b c x dBelow is the perl command that will perform the same:
perl -e '@a=reverse<>;
END{
for(@a){
if(/a/){s/a/c/;last}
}
print reverse @a}' your_file
.png)







I am a software programmer working in India. I usually like to blog in my free time.
0 comments: