Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Location
    Timbaktu
    Posts
    185

    Unanswered: AWK command in Unix

    I want to capture the output of the AWK unix command to a variable, instead of it directing it to the terminal or writing to a file.
    Is it possible?

    My script looks like:
    servername=$1
    username=$2
    awk -F":" -v srvname=$servername -v usrname=$username -v pass=$p '$1~srvname && $4~usrname {print $5} ' inputfilename

    I want to capture print $5 to a variable?

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    The mecanism is the same for all commands :
    variable=`command`

    or variable=$(command) with bash/ksh

    In your case :
    Code:
    servername=$1
    username=$2
    result=$(awk -F":" -v srvname=$servername -v usrname=$username -v pass=$p '$1~srvname && $4~usrname {print $5} ' inputfilename)
    Jean-Pierre.

  3. #3
    Join Date
    May 2002
    Location
    Timbaktu
    Posts
    185
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •