<?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>linux tutorial Archives - Linux Windows and android Tutorials</title>
	<atom:link href="https://www.osradar.com/tag/linux-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.osradar.com</link>
	<description>tutorials and news and Seurity</description>
	<lastBuildDate>Thu, 13 Dec 2018 06:49:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.12</generator>
	<item>
		<title>Uniq on Linux</title>
		<link>https://www.osradar.com/uniq-on-linux/</link>
					<comments>https://www.osradar.com/uniq-on-linux/#respond</comments>
		
		<dc:creator><![CDATA[osradar_editor]]></dc:creator>
		<pubDate>Thu, 13 Dec 2018 06:49:30 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[linux command tutorial]]></category>
		<category><![CDATA[linux tutorial]]></category>
		<category><![CDATA[uniq]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=8336</guid>

					<description><![CDATA[<p>Linux, by default, comes up with a huge collection of handy and powerful tools that can make the life a ton easier. Does your workload requires lots of manipulation of text files and strings? Then you may be already familiar with the “uniq” command. It’s quite common in that type of workspace. Are you new [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/uniq-on-linux/">Uniq on Linux</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Linux, by default, comes up with a huge collection of handy and powerful tools that can make the life a ton easier. Does your workload requires lots of manipulation of text files and strings? Then you may be already familiar with the “uniq” command. It’s quite common in that type of workspace.</p>
<p>Are you new to “uniq”? Don’t worry! Let’s have a look at “uniq” and its usage.</p>
<p>What “uniq” is</p>
<p>Linux comes up with a big collection of tools and features. “uniq” is one of them. The tool works on the command line interface. The purpose of this tool is reporting and/or omitting repeated lines or strings of a file.</p>
<p>The tool just filters adjacent matching from INPUT (standard input) and write out to OUTPUT (standard output). If no option is specified, the tool will merge all the occurrences into the first occurrence.</p>
<h1>Uniq usage</h1>
<p>At first, let’s grab a text file to work with. For demo purpose, my “demo.txt” contains a number of duplicate entries.</p>
<ul>
<li>
<h3>Omitting duplicates on a file</h3>
</li>
</ul>
<pre class="">bat demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8338 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-1.png" alt="" width="1039" height="336" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-1.png 1039w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-1-300x97.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-1-768x248.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-1-1024x331.png 1024w" sizes="(max-width: 1039px) 100vw, 1039px" /></p>
<p><em>Note – Instead of “cat”, I’m using <a href="https://www.osradar.com/bat-advanced-cat-for-linux/">“bat” – a beautiful clone of “cat” with additional advanced features</a>.</em></p>
<p>Now, open up the file with “uniq” –</p>
<pre class="">uniq demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8339 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-2.png" alt="" width="1045" height="479" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-2.png 1045w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-2-300x138.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-2-768x352.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-2-1024x469.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-2-916x420.png 916w" sizes="(max-width: 1045px) 100vw, 1045px" /></p>
<ul>
<li>
<h3>Displaying the number of repetition</h3>
</li>
</ul>
<p>Using the “-c” flag, you can also ask “uniq” how many times a repeated line is repeated.</p>
<pre class="">bat demo.txt

uniq -c demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8340 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-3.png" alt="" width="1039" height="480" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-3.png 1039w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-3-300x139.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-3-768x355.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-3-1024x473.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-3-909x420.png 909w" sizes="(max-width: 1039px) 100vw, 1039px" /></p>
<ul>
<li>
<h3>Printing the “duplicates” ONLY</h3>
</li>
</ul>
<p>Need to figure out the duplicates ONLY? Then use the “-d” flag with “uniq”.</p>
<pre class="">bat demo.txt

uniq -d demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8341 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-4.png" alt="" width="1041" height="387" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-4.png 1041w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-4-300x112.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-4-768x286.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-4-1024x381.png 1024w" sizes="(max-width: 1041px) 100vw, 1041px" /></p>
<ul>
<li>
<h3>Printing the “unique” ONLY</h3>
</li>
</ul>
<p>If you need to work with the unique lines ONLY, then you should use the “-u” flag.</p>
<pre class="">bat demo.txt

uniq -u demo.txt</pre>
<p>&nbsp;</p>
<p><img loading="lazy" class="size-full wp-image-8346 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-9.png" alt="" width="1051" height="452" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-9.png 1051w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-9-300x129.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-9-768x330.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-9-1024x440.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-9-977x420.png 977w" sizes="(max-width: 1051px) 100vw, 1051px" /></p>
<ul>
<li>
<h3>Disable case sensitivity</h3>
</li>
</ul>
<p>When “uniq” is checking the strings, all the characters are case-sensitive, so, “Viktor” and “viktor” are different entry. Need to disable the case sensitivity? Then use the “-i” parameter.</p>
<pre class="">bat demo.txt

uniq -i demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8342 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-5.png" alt="" width="1039" height="491" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-5.png 1039w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-5-300x142.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-5-768x363.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-5-1024x484.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-5-889x420.png 889w" sizes="(max-width: 1039px) 100vw, 1039px" /></p>
<ul>
<li>
<h3>Sorting and finding duplicates</h3>
</li>
</ul>
<p>In most of the cases, the duplicates may be scattered throughout the entire file. When you use “uniq” on that file, it can be misleading and confusing. So, what to do?</p>
<p>Well, sort out the file contents first and then, do the “uniq” thing!</p>
<pre class="">bat demo.txt

sort demo.txt | uniq -c</pre>
<p><img loading="lazy" class="size-full wp-image-8343 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-6.png" alt="" width="1043" height="479" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-6.png 1043w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-6-300x138.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-6-768x353.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-6-1024x470.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-6-915x420.png 915w" sizes="(max-width: 1043px) 100vw, 1043px" /></p>
<ul>
<li>
<h3>Ignoring characters</h3>
</li>
</ul>
<p>In cases, you may need to ignore the presence of a first few characters in the file. In that case, use the “-s” flag followed by the number of character you’d like to omit from the OUTPUT.</p>
<p>bat demo.txt</p>
<pre class="">uniq -s 3 demo.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8344 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-7.png" alt="" width="1041" height="472" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-7.png 1041w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-7-300x136.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-7-768x348.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-7-1024x464.png 1024w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-7-926x420.png 926w" sizes="(max-width: 1041px) 100vw, 1041px" /></p>
<ul>
<li>
<h3>Exporting the output to a file</h3>
</li>
</ul>
<p>It’s quite easy to export the output of any command into a file. Just <a href="https://www.osradar.com/export-linux-command-outputs-to-a-file/">check out this awesome tutorial on exporting command output to a file</a>.</p>
<pre class="">uniq -u demo.txt &gt; demo-1.txt

bat demo-1.txt</pre>
<p><img loading="lazy" class="size-full wp-image-8345 aligncenter" src="https://www.osradar.com/wp-content/uploads/2018/12/uniq-8.png" alt="" width="1046" height="265" srcset="https://www.osradar.com/wp-content/uploads/2018/12/uniq-8.png 1046w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-8-300x76.png 300w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-8-768x195.png 768w, https://www.osradar.com/wp-content/uploads/2018/12/uniq-8-1024x259.png 1024w" sizes="(max-width: 1046px) 100vw, 1046px" /></p>
<p>Enjoy!</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/uniq-on-linux/">Uniq on Linux</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/uniq-on-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
