2

I have this awk command that I need to put a date variable in. I'm sure I'm missing some syntax somewhere. Can any experts help me out? Basicaly, I need the date to be variable depending on when the script is run.

date=$(date --date="1 month ago" +"%d-%b-%Y")
wget -qO - http://*********/users.csv > users
awk      'NR==1          {print "Primary Comments,Customer Account Number,Transaction Date,Service Description,Quantity,Unit,Price,Service Category,PI\x27sName,Purchaser\x27s Last Name,Short Contributing Center Name,Resource Name,Line Item Assistant,Line Item Comments"}
          FNR==NR        {S[$1]=$2; P[$1]=$3; next}
          $1 in S        {print "Bruker 500 NMR",P[$1],date,"500 MHz",$2/60,"Hour","5","500 MHz",S[$1],$1,"","501 NMR","","" }
          ' FS="," OFS="," OFMT="%.2f" $date users FS=" " wtmp > billing-$inst-$date.csv

1 Answer 1

5

Use the -v option.

awk -v date="$date" ....

But GNU awk (gawk) has its own time functions, which are documented here: http://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html

Sign up to request clarification or add additional context in comments.

2 Comments

Was going to answer the same thing. And to add some more sanity to the script, I highly recommend storing the AWK part in a separate file and then doing awk -v date="$date" -f myscript.awk ...
Thanks! I was trying to use the -v option but I kept getting an error. I've figured it out though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.