<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" <crichey@gmail.com><br>To: "CLUE technical discussion" <clue-tech@cluedenver.org><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 <ockers@ockers.net> wrote:<br>> Hi David,<br>><br>> [ockers@agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk '{print<br>> $NF}'<br>> theotherthing<br>><br>> [ockers@agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk '{print<br>> $2 "," $3 "," $4}'<br>> that1,that2,that3<br>><br>> NF means "number of fields" and is a numerical value equal to the number of<br>> whitespace-separated list items. Obviously "theotherthing" is $5. Also -F<br>> command line option to awk indicates the field separator, by default it uses<br>> whitespace as the field separator.<br>><br>> If you want to do something fancy you should know that awk is very powerful<br>> and supports "for" loops. If you want to know the loop iterator syntax I<br>> can suggest that too, but you didn't ask for that.<br>><br>> No perl! :) awk is great for simple text processing.<br>><br>> HTH,<br>> Jim<br>><br>> --<br>> Jim Ockers, P.Eng. (ockers@ockers.net)<br>> Contact info: http://www.ockers.ca/pason.html<br>><br>> David L. Willson wrote:<br>><br>> given lines of the form:<br>> this that1 that2 that3 theotherthing<br>><br>> where the field separator is any combination of spaces and tabs<br>> and there may be 0-9 that's<br>><br>> how do I reliably capture theotherthing, and make a packed, comma-separated<br>> list of all the that's.<br>><br>> This is where I really wish I'd paid more attention in perl class.<br>> Bonus point for not using any perl... :-)<br>><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> If you fill your heart with regrets of yesterday and the worries<br> of tomorrow, you have no today to be thankful for.<br>_______________________________________________<br><br>That's a good idea. I've written complex programs in awk and I've done one-liners. I've never tried to give a talk on it. How thorough would you like?<br><br></div></body></html>