[clue-tech] [spam?] text processing howto
Jim Ockers
ockers at ockers.net
Wed Oct 6 06:36:38 MDT 2010
Hi David,
[ockers at agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk
'{print $NF}'
theotherthing
[ockers at agadez ~]$ echo "this that1 that2 that3 theotherthing" | awk
'{print $2 "," $3 "," $4}'
that1,that2,that3
NF means "number of fields" and is a numerical value equal to the number
of whitespace-separated list items. Obviously "theotherthing" is $5.
Also -F command line option to awk indicates the field separator, by
default it uses whitespace as the field separator.
If you want to do something fancy you should know that awk is very
powerful and supports "for" loops. If you want to know the loop
iterator syntax I can suggest that too, but you didn't ask for that.
No perl! :) awk is great for simple text processing.
HTH,
Jim
--
Jim Ockers, P.Eng. (ockers at ockers.net)
Contact info: http://www.ockers.ca/pason.html
David L. Willson wrote:
> given lines of the form:
> this that1 that2 that3 theotherthing
>
> where the field separator is any combination of spaces and tabs
> and there may be 0-9 that's
>
> how do I reliably capture theotherthing, and make a packed,
> comma-separated list of all the that's.
>
> This is where I really wish I'd paid more attention in perl class.
> Bonus point for not using any perl... :-)
>
> David L. Willson
> Trainer, Engineer, Enthusiast
> MCT MSCE Network+ A+ Linux+ LPIC-1 NovellCLA UbuntuCP
> tel://720.333.LANS
> Freeing people from the tyranny (or whatevery) of Microsofty-ness
> ------------------------------------------------------------------------
>
> _______________________________________________
> clue-tech mailing list
> clue-tech at cluedenver.org
> http://cluedenver.org/mailman/listinfo/clue-tech
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue-tech/attachments/20101006/e601aa80/attachment.html
More information about the clue-tech
mailing list