Awk & parameters - Unix

This is a discussion on Awk & parameters - Unix ; hi all i am passing a parameter to file by the following sh myfile 3 4 7 this would indicate there are threee parameter. and that i want to display the 3rd, 4th and 7th colum in the file mybook. ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Awk & parameters

  1. Awk & parameters

    hi all

    i am passing a parameter to file by the following

    sh myfile 3 4 7

    this would indicate there are threee parameter. and that i want to
    display the 3rd, 4th and 7th colum in the file mybook.
    how can i get the awk command to read $1 as the parameter value (which
    is 3 in this case) and not simply interpreting it as the first column.

    num_parameters=$#
    echo "number of para is $num_parameters"
    echo "dollar 1 : $1"
    echo "dollar 2 : $2"
    echo "dollar 3 : $3"

    IFS=:

    awk -F: '{print $1, $2, $3}' MYBOOK


  2. Re: Awk & parameters

    On 2005-12-07, ronancarty@gmail.com wrote:
    > hi all
    >
    > i am passing a parameter to file by the following
    >
    > sh myfile 3 4 7
    >
    > this would indicate there are threee parameter. and that i want to
    > display the 3rd, 4th and 7th colum in the file mybook.
    > how can i get the awk command to read $1 as the parameter value (which
    > is 3 in this case) and not simply interpreting it as the first column.
    >
    > num_parameters=$#
    > echo "number of para is $num_parameters"
    > echo "dollar 1 : $1"
    > echo "dollar 2 : $2"
    > echo "dollar 3 : $3"
    >
    > IFS=:
    >
    > awk -F: '{print $1, $2, $3}' MYBOOK


    awk -F: -v A="$1" -v B="$2" -v C="$3" '{print $A, $B, $C}' MYBOOK

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

+ Reply to Thread