<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: How to Count Word Occurrences in a Text File	</title>
	<atom:link href="https://www.tecmint.com/count-word-occurrences-in-linux-text-file/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/</link>
	<description>Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks.</description>
	<lastBuildDate>Thu, 13 Jul 2023 13:02:46 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: Ravi Saive		</title>
		<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-2014172</link>

		<dc:creator><![CDATA[Ravi Saive]]></dc:creator>
		<pubDate>Mon, 15 May 2023 03:50:16 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=32730#comment-2014172</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-2014007&quot;&gt;Technotron&lt;/a&gt;.

@Technotron,

We&#039;ve used &lt;strong&gt;Fira Code&lt;/strong&gt; font for our Linux terminal...]]></description>
			<content:encoded><![CDATA[<p>In reply to <a target="_blank" href="https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-2014007">Technotron</a>.</p>
<p>@Technotron,</p>
<p>We&#8217;ve used <strong>Fira Code</strong> font for our Linux terminal&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Technotron		</title>
		<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-2014007</link>

		<dc:creator><![CDATA[Technotron]]></dc:creator>
		<pubDate>Sun, 14 May 2023 14:41:12 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=32730#comment-2014007</guid>

					<description><![CDATA[What is your console font?]]></description>
			<content:encoded><![CDATA[<p>What is your console font?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: rob		</title>
		<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-1491345</link>

		<dc:creator><![CDATA[rob]]></dc:creator>
		<pubDate>Sat, 15 May 2021 23:51:14 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=32730#comment-1491345</guid>

					<description><![CDATA[It&#039;s not perfect but I adapted the &#039;&lt;strong&gt;tr&lt;/strong&gt;&#039; approach to print a count of each word in some standard input:
&lt;pre&gt;
tr -c &quot;&#039;[:alnum:]&quot; &quot;\n&quot; &#124; grep &quot;[[:alnum:]]&quot; &#124; sort &#124; uniq -c &#124; sort -n
&lt;/pre&gt;
While &lt;strong&gt;grep -c&lt;/strong&gt; works on a line, this puts every word or number on its own line and sorts them. Then &lt;strong&gt;uniq -c&lt;/strong&gt; deduplicates them as well as printing the number of occurrences. grep is used to remove blank lines only because if you don&#039;t, uniq prints out the number of blank lines as well, and I didn&#039;t yet come up with a better way to do that. 

The final sort is optional, used to list the words by frequency of appearance instead of alphanumerically. Note the apostrophe in the first set given to tr such that possessives and contractions remain whole words but parenthesis, quotation marks, and other punctuation are stripped off. Also note that this breaks on longer, comma-separated numbers, turning each group into a (probably meaningless) lone 1-, 2-, or 3-digit number. So just don&#039;t try to handle those as though they are words, and there is no problem.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not perfect but I adapted the &#8216;<strong>tr</strong>&#8216; approach to print a count of each word in some standard input:</p>
<pre>
tr -c "'[:alnum:]" "\n" | grep "[[:alnum:]]" | sort | uniq -c | sort -n
</pre>
<p>While <strong>grep -c</strong> works on a line, this puts every word or number on its own line and sorts them. Then <strong>uniq -c</strong> deduplicates them as well as printing the number of occurrences. grep is used to remove blank lines only because if you don&#8217;t, uniq prints out the number of blank lines as well, and I didn&#8217;t yet come up with a better way to do that. </p>
<p>The final sort is optional, used to list the words by frequency of appearance instead of alphanumerically. Note the apostrophe in the first set given to tr such that possessives and contractions remain whole words but parenthesis, quotation marks, and other punctuation are stripped off. Also note that this breaks on longer, comma-separated numbers, turning each group into a (probably meaningless) lone 1-, 2-, or 3-digit number. So just don&#8217;t try to handle those as though they are words, and there is no problem.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Martins Okoi		</title>
		<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-1158768</link>

		<dc:creator><![CDATA[Martins Okoi]]></dc:creator>
		<pubDate>Thu, 30 May 2019 08:45:16 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=32730#comment-1158768</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-1158597&quot;&gt;Denis&lt;/a&gt;.

Awesome!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a target="_blank" href="https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-1158597">Denis</a>.</p>
<p>Awesome!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Denis		</title>
		<link>https://www.tecmint.com/count-word-occurrences-in-linux-text-file/comment-page-1/#comment-1158597</link>

		<dc:creator><![CDATA[Denis]]></dc:creator>
		<pubDate>Wed, 29 May 2019 09:34:03 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=32730#comment-1158597</guid>

					<description><![CDATA[I use Silver Searcher (https://geoff.greer.fm/ag/), which is capable to search &lt;strong&gt;~1TB&lt;/strong&gt; file in less than a second.
&lt;ul&gt;
&lt;li&gt;To print all found entries: &lt;strong&gt;ag -i mauris example.txt&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;To only count all entries: &lt;strong&gt;ag -c mauris example.txt&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
Give it a try...]]></description>
			<content:encoded><![CDATA[<p>I use Silver Searcher (<a target="_blank" href="https://geoff.greer.fm/ag/" rel="nofollow ugc">https://geoff.greer.fm/ag/</a>), which is capable to search <strong>~1TB</strong> file in less than a second.</p>
<ul>
<li>To print all found entries: <strong>ag -i mauris example.txt</strong></li>
<li>To only count all entries: <strong>ag -c mauris example.txt</strong></li>
</ul>
<p>Give it a try&#8230;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
