<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.christophchamp.com/index.php?action=history&amp;feed=atom&amp;title=Awk%2Ftips_and_tricks</id>
		<title>Awk/tips and tricks - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.christophchamp.com/index.php?action=history&amp;feed=atom&amp;title=Awk%2Ftips_and_tricks"/>
		<link rel="alternate" type="text/html" href="http://wiki.christophchamp.com/index.php?title=Awk/tips_and_tricks&amp;action=history"/>
		<updated>2026-04-30T12:21:27Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://wiki.christophchamp.com/index.php?title=Awk/tips_and_tricks&amp;diff=5380&amp;oldid=prev</id>
		<title>Christoph: New page: This article will list random &quot;tips &amp; tricks&quot; in using awk/gawk.  *List the directories and files in the current directory such that they can be distinguished with a trailing '/' (-F f...</title>
		<link rel="alternate" type="text/html" href="http://wiki.christophchamp.com/index.php?title=Awk/tips_and_tricks&amp;diff=5380&amp;oldid=prev"/>
				<updated>2010-01-09T17:25:49Z</updated>
		
		<summary type="html">&lt;p&gt;New page: This article will list random &amp;quot;tips &amp;amp; tricks&amp;quot; in using &lt;a href=&quot;/index.php?title=Awk&quot; title=&quot;Awk&quot;&gt;awk&lt;/a&gt;/gawk.  *List the directories and files in the current directory such that they can be distinguished with a trailing &amp;#039;/&amp;#039; (-F f...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article will list random &amp;quot;tips &amp;amp; tricks&amp;quot; in using [[awk]]/gawk.&lt;br /&gt;
&lt;br /&gt;
*List the directories and files in the current directory such that they can be distinguished with a trailing '/' (-F flag), identify the directories by grepping for the trailing '/' and pull out only those rows, remove the trailing slash with sed, use awk to build a command line that will tar up the directory, and finally execute the whole shebang by piping it to bash.&lt;br /&gt;
&lt;br /&gt;
 ls -F | grep '\/$' | sed 's/\/$//g' | awk '{print &amp;quot;tar -xf &amp;quot;$0&amp;quot; &amp;quot;$0&amp;quot;.tar&amp;quot;;}' | bash&lt;br /&gt;
&lt;br /&gt;
*The &amp;quot;proper&amp;quot; way to do this is with the while construct; however, the disadvantage of this is that you can't preview the command sequence quite as easily.&lt;br /&gt;
&lt;br /&gt;
 ls -F | grep '\/$' | sed 's/\/$//g' | while read filename; do tar -xf &amp;quot;${filename}&amp;quot; &amp;quot;${filename}.tar&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
*Find the files in the subdirectories below the current directory, grep for those that end with a trailing '&amp;lt;code&amp;gt;.txt&amp;lt;/code&amp;gt;', take the top 30 lines of each of these files, and pipe the result to less so you can page through the results.&lt;br /&gt;
&lt;br /&gt;
 find ./ | grep '\.txt$' | xargs head -30 | less&lt;br /&gt;
&lt;br /&gt;
*Find all the rows where the 5th column does not equal &amp;quot;&amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt;&amp;quot; in the file &amp;lt;code&amp;gt;foo.txt&amp;lt;/code&amp;gt;, cut out the resulting columns 1-5 among the resulting rows, sort the result by the 1st column with a reverse (&amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt;) numeric (&amp;lt;code&amp;gt;-n&amp;lt;/code&amp;gt;) sort, retain only those lines which are not adjacent to identical lines, and print out the resulting number of lines with &amp;lt;code&amp;gt;wc -l&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 awk '{if ($5 != -1) { print;}}' demo.txt | cut -f1-5 | sort -k1 -r -n | uniq | wc -l&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting languages]]&lt;/div&gt;</summary>
		<author><name>Christoph</name></author>	</entry>

	</feed>