<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial; font-size: 12pt; color: #000000'><br>----- Original Message -----<br>From: "Collins Richey" &lt;crichey@gmail.com&gt;<br>To: "CLUE technical discussion" &lt;clue-tech@cluedenver.org&gt;<br>Sent: Wednesday, October 6, 2010 5:36:39 PM<br>Subject: Re: [clue-tech] [spam?] text processing howto<br><br>On Wed, Oct 6, 2010 at 7:36 AM, Jim Ockers &lt;ockers@ockers.net&gt; wrote:<br>&gt; Hi David,<br>&gt;<br>&gt; [ockers@agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk '{print<br>&gt; $NF}'<br>&gt; theotherthing<br>&gt;<br>&gt; [ockers@agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk '{print<br>&gt; $2 "," $3 "," $4}'<br>&gt; that1,that2,that3<br>&gt;<br>&gt; NF means "number of fields" and is a numerical value equal to the number of<br>&gt; whitespace-separated list items.&nbsp; Obviously "theotherthing" is $5.&nbsp; Also -F<br>&gt; command line option to awk indicates the field separator, by default it uses<br>&gt; whitespace as the field separator.<br>&gt;<br>&gt; If you want to do something fancy you should know that awk is very powerful<br>&gt; and supports "for" loops.&nbsp; If you want to know the loop iterator syntax I<br>&gt; can suggest that too, but you didn't ask for that.<br>&gt;<br>&gt; No perl! :)&nbsp; awk is great for simple text processing.<br>&gt;<br>&gt; HTH,<br>&gt; Jim<br>&gt;<br>&gt; --<br>&gt; Jim Ockers, P.Eng. (ockers@ockers.net)<br>&gt; Contact info: http://www.ockers.ca/pason.html<br>&gt;<br>&gt; David L. Willson wrote:<br>&gt;<br>&gt; given lines of the form:<br>&gt; &nbsp;&nbsp;&nbsp; this that1 that2 that3 theotherthing<br>&gt;<br>&gt; where the field separator is any combination of spaces and tabs<br>&gt; and there may be 0-9 that's<br>&gt;<br>&gt; how do I reliably capture theotherthing, and make a packed, comma-separated<br>&gt; list of all the that's.<br>&gt;<br>&gt; This is where I really wish I'd paid more attention in perl class.<br>&gt; Bonus point for not using any perl...&nbsp; :-)<br>&gt;<br><br>You can do the same thing in two lines of perl. I won't bore you with<br>the power of pcre engines, but this has been adopted by the likes of<br>php, ruby, and even Windows Powershell (ugh!!!).<br><br>BTW, I would love to see a thorough presentation of AWK as a topic for<br>a CLUE meeting. AWK is indeed a powreful utility, but I, for one, have<br>always been too lazy to learn it!<br><br><br>-- <br>Collins Richey<br>&nbsp; &nbsp;&nbsp; If you fill your heart with regrets of yesterday and the worries<br>&nbsp; &nbsp;&nbsp; of tomorrow, you have no today to be thankful for.<br>_______________________________________________<br><br>That's a good idea.&nbsp; I've written complex programs in awk and I've done one-liners.&nbsp; I've never tried to give a talk on it.&nbsp; How thorough would you like?<br><br></div></body></html>