Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

245.Advanced search and replace -- How to replace the last occurance of some text like 'abc' to 'def' in a text file?

User: editor -- 2008-08-09          << 244  246 >>
Hits: 2943
Type: Advanced search and replace   
Search all Advanced search and replace examples
How to replace the last occurance of some text like 'abc' to 'def' in a text file?
Input Sample:
first occurance of abc 
second occurance of abc 
other text 
last occurance of abc 
other text
Output Sample:
first occurance of abc 
second occurance of abc 
other text 
last occurance of def 
other text
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
1. ctrl-o open text file 
2. ctrl-h open 'Replace' dialog 
set "Search for pattern" to: 
set "Replace with Pattern" to: 
3. click 'Replace', done! 
Note: .*?abc will match from beginning to first 'abc', .*abc will match from beginning to last 'abc'. 
chars($match,1,-4) means keep from 1st to -4th characters(remove last 3 chars:abc) 
** For newer version, you can search "(.*)abc" and replace with "\1def"
Download Script:  scripts/

Screenshot 1:  Replace_Window

Similar Examples:
How to replace the last occurance of 'old' in every line with 'new'? (67%)
How to replace each xxx with the first word in the same line in text file? (61%)
How to count the occurrence of a list of words in a text file? (60%)
How to replace text containing some special symbols in a text file? (59%)
How to replace specified occurrance of some string to a list of words? (58%)
How to count and sort the occurrence of different numbers in a text file? (58%)
How to count the occurrance of specific pattern in each line of text file? (58%)
How to replace every 3 instances found in a text file? (58%)

Check Demo of Advanced search and replace
logs  4th  occurance  1st  toc  abc  remove last  keep  the last  last  replace first occurance  first occurance  replace 1st occurance  replace first abc with def  replace abc def  keep first  keep last  replace first last