Unix AWK programming Question - Unix

This is a discussion on Unix AWK programming Question - Unix ; Hi Everyone, I have written the following script to extract certain information from the /etc/passwd file for i in `awk -F: '($3 >= 500) { print $6 }' /etc/passwd`; do echo $i done While this script works printing the home ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Unix AWK programming Question

  1. Unix AWK programming Question

    Hi Everyone,

    I have written the following script to extract certain information
    from the /etc/passwd file

    for i in `awk -F: '($3 >= 500) { print $6 }' /etc/passwd`; do

    echo $i
    done

    While this script works printing the home directory as $6, I want to
    use $1 for that particular line to use as a title for each user. I
    want to assign $1 in the awk statement to a BASH shell variable.

    Any idea.s


  2. Re: Unix AWK programming Question

    Hi Tommy!

    Tommy wrote:
    > I have written the following script to extract certain information
    > from the /etc/passwd file
    >
    > for i in `awk -F: '($3 >= 500) { print $6 }' /etc/passwd`; do
    >
    > echo $i
    > done
    >
    > While this script works printing the home directory as $6, I want to
    > use $1 for that particular line to use as a title for each user. I
    > want to assign $1 in the awk statement to a BASH shell variable.

    ??? Not quite sure if I got you right...

    --- snip -------------------------
    eval $(awk -F: '($3 >= 500) {printf("export %s=%s\n", $1,$6)}' /etc/passwd)
    --- snap -------------------------
    Would give something like the following...
    export messagebus=/var/run/dbus
    export mysql=/var/lib/mysql
    export nagios=/var/lib/nagios
    export named=/var/lib/named
    export nobody=/var/lib/nobody

    and that would get evaluated...
    (you are talking bash, do you? ;-)

    HTH. Salut, Joerg

    --
    gpg/pgp key # 0xd7fa4512
    fingerprint 4e89 6967 9cb2 f548 a806 7e8b fcf4 2053 d7fa 4512

+ Reply to Thread