[CentOS] script help - '3rd last field'

James Bensley jwbensley at gmail.com
Mon Jun 8 09:42:37 UTC 2009


Is there anyway you can tell which field it will be in (i.e. to use as
a search clause, so "search for the field with X properties"?)

Ultimately to get the data in the X'th field you are going to need
either awk or sed (they can both easily do this, awk probably easier
than sed)

You need to work out how you will know which field it will be in i.e.
the first, second, third? My shell scripting is rubbish but I would
guess it would go something like;

myString = "first.second.VALUE.fourth.fith"

awk -F\. {'print 3'} myString

This would print the third field seperated by a '.' (full stop/period)
of myString

That's a rubbishy wild stab in the dark as im rubbish at shell scripting.

I would actually bet money I have made things more complex hahahah!

Sorry, i tried :'(

James.

-----BEGIN GEEK CODE BLOCK-----
  Version: 3.1
GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V-
PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++
------END GEEK CODE BLOCK------



More information about the CentOS mailing list