Korn shell scripting problem - Aix

This is a discussion on Korn shell scripting problem - Aix ; In the K shell script below I want to extract the values for forms, address and jobid into seperate variables. The variables can appear in any order and can be of any length. I can extract the forms value OK, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Korn shell scripting problem

  1. Korn shell scripting problem

    In the K shell script below I want to extract the values for forms,
    address and jobid into seperate variables. The variables can appear in
    any order and can be of any length.

    I can extract the forms value OK, but nothing else. And that probebaly
    only works because it is the first variable.

    Can anyone help?



    IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"

    FORMSTRING=${IN#forms=*}
    echo $FORMSTRING
    FORM=${FORMSTRING%%,*}
    echo $FORM
    ADDRESSSTRING=${IN##address=*}
    echo $ADDRESSSTRING
    ADDRESS=${ADDRESSSTRING%%,*}
    echo $ADDRESS


  2. Re: Korn shell scripting problem

    Loial wrote:
    > In the K shell script below I want to extract the values for forms,
    > address and jobid into seperate variables. The variables can appear in
    > any order and can be of any length.
    >
    > I can extract the forms value OK, but nothing else. And that probebaly
    > only works because it is the first variable.


    > IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"


    Are the values ALWAYS separated by commas? If so, try this:

    FORM=$(echo $IN |tr -s ',' '\n' | grep "forms=" |cut -f2 -d'=')
    CLASS=$(echo $IN |tr -s ',' '\n' | grep "class=" |cut -f2 -d'=')
    ....and so on...

    Not the prettiest way, but it works. You could also probably use a
    while..read..do loop to be cleaner.

    HTH

    Steve


  3. Re: Korn shell scripting problem

    Loial wrote:
    > In the K shell script below I want to extract the values for forms,
    > address and jobid into seperate variables. The variables can appear in
    > any order and can be of any length.
    >
    > I can extract the forms value OK, but nothing else. And that probebaly
    > only works because it is the first variable.
    >
    > Can anyone help?


    This should work in most shells. Depending on what version you have,
    there are better ways. Merry Christmas. Good luck in the class

    IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"
    IFS="IFS = ,"
    set $IN
    echo $6
    shift 3
    echo $9


    >
    >
    >
    > IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"
    >
    > FORMSTRING=${IN#forms=*}
    > echo $FORMSTRING
    > FORM=${FORMSTRING%%,*}
    > echo $FORM
    > ADDRESSSTRING=${IN##address=*}
    > echo $ADDRESSSTRING
    > ADDRESS=${ADDRESSSTRING%%,*}
    > echo $ADDRESS
    >


  4. Re: Korn shell scripting problem

    base60 wrote:
    > Loial wrote:
    >> In the K shell script below I want to extract the values for forms,
    >> address and jobid into seperate variables. The variables can appear in
    >> any order and can be of any length.
    >>
    >> I can extract the forms value OK, but nothing else. And that probebaly
    >> only works because it is the first variable.
    >>
    >> Can anyone help?

    >
    > This should work in most shells. Depending on what version you have,
    > there are better ways. Merry Christmas. Good luck in the class
    >
    > IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"
    >
    > IFS="IFS = ,"


    Yes, typo... still works, though.

    > set $IN
    > echo $6
    > shift 3
    > echo $9
    >
    >
    >>
    >>
    >>
    >> IN="forms=1000,class=M,address=12345678901234567890123 452008ZZZ,destination=CYCLE3,outgrp_name=BATCH3,jo bid=JOB33103"
    >>
    >>
    >> FORMSTRING=${IN#forms=*}
    >> echo $FORMSTRING
    >> FORM=${FORMSTRING%%,*}
    >> echo $FORM
    >> ADDRESSSTRING=${IN##address=*}
    >> echo $ADDRESSSTRING
    >> ADDRESS=${ADDRESSSTRING%%,*}
    >> echo $ADDRESS
    >>


+ Reply to Thread