<?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>I Can Has Linux? &#187; xargs</title>
	<atom:link href="http://icanhaslinux.com/category/xargs/feed/" rel="self" type="application/rss+xml" />
	<link>http://icanhaslinux.com</link>
	<description>Invisible Patent Infringement!</description>
	<lastBuildDate>Mon, 29 Aug 2011 13:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>De-RIAAing my music collection</title>
		<link>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/</link>
		<comments>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 15:34:00 +0000</pubDate>
		<dc:creator>LightningCrash</dc:creator>
				<category><![CDATA[awk]]></category>
		<category><![CDATA[findutils]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[riaa]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/</guid>
		<description><![CDATA[I recently decided that I won&#8217;t own any music from an artist that is represented by the RIAA. Now, how do I go about De-RIAAing my ripped albums? RIAA Radar has a website that will let you search for artists, albums, keywords, etc and it will give you information as to whether or not an [...]]]></description>
			<content:encoded><![CDATA[<p align="left">I recently decided that I won&#8217;t own any music from an artist that is represented by the RIAA. Now, how do I go about De-RIAAing my ripped albums?</p>
<p align="left"><a href="http://www.riaaradar.com/">RIAA Radar</a> has a website that will let you search for artists, albums, keywords, etc and it will give you information as to whether or not an album was released under the RIAA.</p>
<p align="left">So I did a view-source on their search page and determined that there are only three variables that you need to POST in order to search: searchtype, keyword, and submit.</p>
<p align="left">I can use wget to grab the file, like so:<br />
<code>wget http://www.riaaradar.com/search.asp --post-data "searchtype=ArtistSearch&amp;keyword=Audioslave&amp;submit=Go\!" -O Audioslave</code></p>
<p align="left">This saves the file as Audioslave. Audioslave IS represented by the RIAA, by the way.</p>
<p align="left">Now, how do I take my ripped albums and compare them to the RIAA Radar site?</p>
<p align="left"><span id="more-59"></span><br />
In my album collection, all of the albums are formatted the same: Artist &#8211; Album Name<br />
This little bit of effort a long time ago makes it easy for me to separate these now.<br />
I simply cd into my albums directory and do the following:<br />
<code>ls|awk '{FS="-"};{ print $1}'|uniq &gt;&gt; artists</code></p>
<p align="left">I now have a file called artists in my album collection that contains unique artist names for every album in the collection.</p>
<p align="left">Now, to find out if they&#8217;re represented by the RIAA:</p>
<p align="left"><code>cat artists|tr " " "+"|xargs -i wget http://www.riaaradar.com/search.asp --post-data "searchtype=ArtistSearch&amp;keyword={}&amp;submit=Go\!" -O radarresults{}.html</code></p>
<p align="left">This will pull down the search result for every artist in my album list, and save it in a file formatted the way I want.<br />
For instance, Jimi Hendrix would be saved as radarresultsJimi+Hendrix.html</p>
<p align="left">I browse this with lynx and see that the text &#8220;Warning!&#8221; would be pretty good to search on.</p>
<p align="left"><code>grep Warning! radarresults*|sed -e 's/&lt;[^&lt;&gt;]*&gt;//g'|tr "+" " "|cut -c 13-|uniq|awk '{FS=".html"};{print $1}' &gt;&gt; riaapunks.txt</code></p>
<p align="left">Explanation: grep searches the files for Warning!, then sed strips out the html. tr converts those + signs to spaces, cut trims off the radarresults portion of the output, uniq filters out duplicates, awk cuts off everything after and including .html, then it all gets dumped to a file.</p>
<p align="left">Now I&#8217;ve got a nice list of everyone who is represented by the RIAA, in a file called riaapunks.txt</p>
<p align="left">Now I get to have fun with it!<br />
<code>cat riaapunks.txt|xargs --verbose -i find ./ -name *{}* </code></p>
<p align="left">Output looks good. Now for the coup de grace:<br />
<code>cat riaapunks.txt|xargs --verbose -i find ./ -name *{}* -delete</code></p>
<p align="left">Buh-bye RIAA music!</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Xargs is your friend</title>
		<link>http://icanhaslinux.com/2007/09/10/xargs-is-your-friend/</link>
		<comments>http://icanhaslinux.com/2007/09/10/xargs-is-your-friend/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 13:09:32 +0000</pubDate>
		<dc:creator>LightningCrash</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://icanhaslinux.com/2007/09/10/xargs-is-your-friend/</guid>
		<description><![CDATA[If you don&#8217;t know what xargs is, here&#8217;s the definition of xargs from Wikipedia: xargs is a command of the Unix and most Unix-like operating systems which eases passing command output to another command as command line arguments. It splits its often piped input at whitespaces (or the null character) and calls the command given [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t know what xargs is, here&#8217;s the definition of xargs from <a href="http://en.wikipedia.org/wiki/Xargs" target="_blank">Wikipedia</a>:</p>
<blockquote><p>xargs is a command of the Unix and most Unix-like operating systems which eases passing command output to another command as command line arguments.</p>
<p>It splits its often piped input at whitespaces (or the null character) and calls the command given as an argument with each element of the split input as parameter. If the parameter list is too long, it calls the program as often as necessary. It often covers the same functionality as the backquote feature of many shells, but is more flexible and often also safer, especially if there are blanks or special characters in the input.</p>
<p>This is often used in conjunction with the Unix commands find, locate and grep.</p></blockquote>
<p>So, what can you do with xargs?</p>
<p>Well, let&#8217;s say you want to put up a torrent on a tracker, but you want to include a file with the MD5 checksums of every file. We&#8217;ll assume that the files you want to put on bittorrent are in /home/me/mytorrent/<br />
To generate an MD5 sum of every file in the directory and dump it to a file, you can do the following:<br />
<code>find /home/me/mytorrent/ -type f|xargs md5sum &gt;&gt; /home/me/mytorrent/md5sums.txt</code></p>
<p>Now you&#8217;ve got a list of the MD5 sums for every file in the torrent you want to publish.</p>
<p>You can also use xargs to call grep to look inside files. For instance, if you&#8217;re editing a web page and you want to find all instances of a PHP class, you can execute the following:</p>
<p><code>find /home/me/mywebpage -name '*.php'|xargs grep -Hn adminClass</code></p>
<p>This will return a list of each file ending in php, and then for each item in the list, grep will check for the string adminClass. The -H flag will make sure that grep prints the filename in each match, and the -n flag will make grep print the line number as well.</p>
<p>xargs is an invaluable tool in command-line work because it prevents you from having to write a for or while loop in a shell script. xargs will run the command you specify on every line of output. Granted, find has an -exec capability, but xargs has its utility. Being slightly paranoid, you might like to check the output of a command before you pipe it to xargs or run an -exec in find. For instance, if you were removing everything in a cache directory, it would probably be better to pipe the find output to more first, and then after you have verified the output, you can pipe it to xargs rm -f -r</p>
<p>For usenet users, you can also use xargs to PAR check all of your files.</p>
<p><code>ls *.par2|xargs par -r</code></p>
<p>Windows users take heart, there is an xargs for windows in the <a href="http://gnuwin32.sourceforge.net/packages/findutils.htm" target="_blank">Findutils package for Windows</a> .</p>
<p>Have any other xargs tricks? Leave yours in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhaslinux.com/2007/09/10/xargs-is-your-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

