<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tr Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/tr/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/tr/</link>
	<description></description>
	<lastBuildDate>Tue, 04 Sep 2018 05:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>tr Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/tr/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 192. Word Frequency</title>
		<link>https://zxi.mytechroad.com/blog/bash/leetcode-192-word-frequency/</link>
					<comments>https://zxi.mytechroad.com/blog/bash/leetcode-192-word-frequency/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 29 Mar 2018 03:58:39 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[tr]]></category>
		<category><![CDATA[uniq]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2394</guid>

					<description><![CDATA[<p>Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity sake, you may assume: words.txt contains only lowercase characters&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/bash/leetcode-192-word-frequency/">花花酱 LeetCode 192. Word Frequency</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>
<p>For simplicity sake, you may assume:</p>
<ul>
<li><code>words.txt</code> contains only lowercase characters and space <code>' '</code> characters.</li>
<li>Each word must consist of lowercase characters only.</li>
<li>Words are separated by one or more whitespace characters.</li>
</ul>
<p>For example, assume that <code>words.txt</code> has the following content:</p>
<pre class="crayon:false">the day is sunny the the
the sunny is is
</pre>
<p>Your script should output the following, sorted by descending frequency:</p>
<pre class="crayon:false">the 4
is 3
sunny 2
day 1
</pre>
<p><b>Note:</b><br />
Don&#8217;t worry about handling ties, it is guaranteed that each word&#8217;s frequency count is unique.</p>
<h1><strong>Solution</strong></h1>
<p><div class="responsive-tabs">
<h2 class="tabtitle">bash</h2>
<div class="tabcontent">
</p><pre class="crayon-plain-tag"># Author: Huahua
# Running time: 8 ms (beats 99.80%)
cat words.txt | tr -s " " "\n" | sort | uniq -c | sort -r | awk '{print $2, $1}'</pre><p></div></div></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/bash/leetcode-192-word-frequency/">花花酱 LeetCode 192. Word Frequency</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/bash/leetcode-192-word-frequency/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
