Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Posts
    35

    Unanswered: pass variables to awk

    how can I pass a variable to the awk with command line?
    e.g.:

    while read aline
    do
    val=$aline
    awk '{ print $1, $val }' myfile
    done < datafile

    Thanks a lot for your help!

  2. #2
    Join Date
    Jan 2003
    Posts
    19
    either with the -v option on the command line (see man awk) or by taking the variable outside the script ie:
    1) ... awk -v v=$val1 '{print v}'....
    OR
    2) ... awk '{print "'$val1'"}'...

    any help?

Posting Permissions

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