Hi I need some logic to work out a value for me - this value is _always_ the 3rd last field in a string seperated by '.' but the string could be 5 or 6 fields long, e.g foo.bar.VALUE.baz.lala foor.bar.gigi.VALUE.baz.lala I need to find VALUE - if this were python or something i could do it but this has to be in shell - Any clues? thanks
michael.kettel at rm-solutions.de
2009-Jun-08 09:31 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:32 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:33 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:35 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:36 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:37 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
On Mon, Jun 8, 2009 at 4:29 PM, Tom Brown<tom at ng23.net> wrote:> Hi > > I need some logic to work out a value for me - this value is _always_ > the 3rd last field in a string seperated by '.' but the string could be > 5 or 6 fields long, e.g > > foo.bar.VALUE.baz.lala > > foor.bar.gigi.VALUE.baz.lala > > I need to find VALUE - if this were python or something i could do it > but this has to be in shell -awk -F\. {'print $3'} awk -F\. {'print $5'} awk -F\. {'print $6'} -- Muhammad Panji http://sumodirjo.wordpress.com http://www.kurungsiku.web.id
michael.kettel at rm-solutions.de
2009-Jun-08 09:39 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:40 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:41 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
michael.kettel at rm-solutions.de
2009-Jun-08 09:42 UTC
[CentOS] script help - '3rd last field'
Sehr geehrte Damen und Herren, ich bin ab dem 15.06.2009 wieder zur?ck im B?ro. Bitte wenden Sie sich in dringenden F?llen an Simon Schillings [simon.schillings at rm-solutions.de] Viele Gr??e, Michael Kettel
On Mon, Jun 8, 2009 at 5:29 AM, Tom Brown<tom at ng23.net> wrote:> Hi > > I need some logic to work out a value for me - this value is _always_ > the 3rd last field in a string seperated by '.' but the string could be > 5 or 6 fields long, e.g > > foo.bar.VALUE.baz.lala > > foor.bar.gigi.VALUE.baz.lala > > I need to find VALUE - if this were python or something i could do it > but this has to be in shell - > > Any clues? > > thanks > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >I am pretty sure there is a way in awk to figure out how many fields you have, then take the total # of fields -3 each time to get the third last one. Just heading out the door and off hand can't remember how it would be done. Jacques B.
Hi. echo foo.bar.VALUE.baz.lala | awk -F. '{ print $(NF-2); }' -- Alex S.<magicboom at gmail.com> On 08.06.2009 13:29, Tom Brown wrote:> Hi > > I need some logic to work out a value for me - this value is _always_ > the 3rd last field in a string seperated by '.' but the string could be > 5 or 6 fields long, e.g > > foo.bar.VALUE.baz.lala > > foor.bar.gigi.VALUE.baz.lala > > I need to find VALUE - if this were python or something i could do it > but this has to be in shell - > > Any clues? > > thanks > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >
On Mon, 2009-06-08 at 10:29 +0100, Tom Brown wrote:> Hi > > I need some logic to work out a value for me - this value is _always_ > the 3rd last field in a string seperated by '.' but the string could be > 5 or 6 fields long, e.g > > foo.bar.VALUE.baz.lala > > foor.bar.gigi.VALUE.baz.lala > > I need to find VALUE - if this were python or something i could do it > but this has to be in shell - > > Any clues?Without trying to make code this early in the A.M., I'll give an algorithm that will work entirely in shell. Then the man page should give the details. 1. Make a subshell, either as a separate file or inline using braces-type stuff 2. Inside that, use the set command to change the field separator to "." 3. Use the set command with the string use wish to parse. This sets each field into $1, $2, ... 4. Alternate algorithm # 1 Use the shell variable $# (IIRC) to see how many you have. Use the shell's math capabilities to calculate the variable number you want Use the shell to generate a command (eval, backslashes, ...) to reference that variable 5. Alternate algorithm # 2 do a while loop until $# = 3 (if it's already <= to 3, next is skipped shift access $1 6. Alternate algorithm # 3 If $# > 3 use shell math ability to calculate how many shifts needed use shift with that number as parameter access $1> > thanks > <snip sig stuff>HTH -- Bill