Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

476.Character count -- How to count the occurrance of specific pattern in each line of text file?

User: editor -- 2010-04-13
Hits: 90
Type: Character count   
Search all Character count examples
Description:
How to count the occurrance of specific pattern in each line of text file?
I need to count the occurrance of word like "Yes" in each line of source text file, add the number at the end of each line, and put the result in the output file.
Input Sample:
Yes No N/A Yes
N/A Yes No N/A
No Yes Yes Yes
Output Sample:
Yes No N/A Yes 2
N/A Yes No N/A 1
No Yes Yes Yes 3
Answer:
Hint: You need to Download and install "Replace Pioneer" to finish following steps.
1. ctrl-o open source text file
2. ctrl-h open 'replace' window
* set 'replace unit' to 'Line'
* in 'replace with pattern', enter:

3. click 'Replace' button, done.
4. ctrl-s save to output file.

Note: function count will count number of the pattern "Yes" appearred in string $match
Download Script:  scripts/476.rst.zip

Similar Examples:
How to replace specific spaces into comma in each line of text file? (71%)
How to count the occurrance of some specified words in many files? (70%)
How to insert a line after specific lines in a text file? (65%)
How to remove the first 10 characters of each line in text file? (64%)
How to list all specific terms that appearing in a text file? (64%)
How to replace the second character of every line to 4 in a text file? (63%)
How to batch extract specified lines from a text file? (63%)
How to delete the first word in each line in a text file? (63%)

Check Demo of Character count