awk comparison with variable

hi,

I want to compare i variable in the awk statement but its not working out. Pl help me out

If we do the comparison like this its OK,

cat sample | awk -F" ", '{if ($1=="1-Sep-2009") print $1,$2,$3,$4,$5}'

But if u use a variable instead of "1-Sept-2009", it does not return anything,

d1=$(TZ=GMT-24 date +%cc | awk -F" ", '{print $1}')
d1=$(TZ=GMT-24 date +%cc | awk -F" ", '{print $2}')
cat sample | awk -F" ", '{if ($1==($d1"-"$d2"-2009") print $1,$2,$3,$4,$5}'

Pl suggest how can i incorporate this?

Thanks

Hello,

Check this User guide:
The GNU Awk User's Guide

Translated for your problem:

awk -F" " -v d1="$d1" -v d2="$d2" '$1==d1"-"d2"-2009" {print $1,$2,$3,$4,$5}'

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums