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
0 comments: