user1745860
user1745860

Reputation: 247

awk compare value with a input

can a user input variable($userinput) compare with a value?

awk -F:  '$1 < $userinput { printf .... }'

This comparison expression seems ok to me, but it gives an error?

Upvotes: 2

Views: 293

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185105

Try doing this :

awk -vuserinput="$userinput" -F: '$1 < userinput {}'

A real example :

read -p "Give me an integer >>> " int
awk -v input=$int '$1 < input {print $1, "is less than", input}' <<< 1

Upvotes: 6

Related Questions