Count occurrences of a word in string: Difference between revisions

Jump to navigation Jump to search
m
Line 43: Line 43:
== BASH ==
== BASH ==
data preparation
data preparation
* (1) separate each string by [[Return symbol | return_symbol]]  
* (1) separate each string by [[Return symbol | return_symbol]] <ref>[https://www.unix.com/shell-programming-and-scripting/83076-replacing-commas-newlines-using-sed.html replacing comma's with newlines using sed]</ref>
* (2) check the [https://www.computerhope.com/unix/uuniq.htm uniq command] is exists on Cygwin of {{Win}} or {{Linux}}
* (2) check the [https://www.computerhope.com/unix/uuniq.htm uniq command] is exists on Cygwin of {{Win}} or {{Linux}}
* (3) execute the following command {{kbd | key=<nowiki>sort <file.txt> | uniq -ic | sort -nr</nowiki>}}<ref>[https://unix.stackexchange.com/questions/134446/counting-the-occurrences-of-the-string text processing - Counting the occurrences of the string - Unix & Linux Stack Exchange]</ref><ref>[https://unix.stackexchange.com/questions/170043/sort-and-count-number-of-occurrence-of-lines Sort and count number of occurrence of lines - Unix & Linux Stack Exchange]</ref>
* (3) execute the following command {{kbd | key=<nowiki>sort <file.txt> | uniq -ic | sort -nr</nowiki>}}<ref>[https://unix.stackexchange.com/questions/134446/counting-the-occurrences-of-the-string text processing - Counting the occurrences of the string - Unix & Linux Stack Exchange]</ref><ref>[https://unix.stackexchange.com/questions/170043/sort-and-count-number-of-occurrence-of-lines Sort and count number of occurrence of lines - Unix & Linux Stack Exchange]</ref>
Line 57: Line 57:
</pre>
</pre>


Result of the execution of command: {{kbd | key=<nowiki>sort test.txt | uniq -ic | sort -nr</nowiki>}}
Result of the execution of command: {{kbd | key=<nowiki>sort test.txt | uniq -ic | sort -nr</nowiki>}} {{exclaim}} insensitive
<pre>
<pre>
   2 #Apple
   2 #Apple
Line 66: Line 66:
</pre>
</pre>


Result of the execution of command: {{kbd | key=<nowiki>sort test.txt | uniq -c</nowiki>}}
Result of the execution of command: {{kbd | key=<nowiki>sort test.txt | uniq -c</nowiki>}} {{exclaim}} sensitive
<pre>
<pre>
   1 #Apple
   1 #Apple

Navigation menu