getline value to pattern

BEGIN {
system("clear")
blank = " "
printf("Please enter your name or emp# : > ")
getline < "/dev/tty"
printf(">>>>> %s",$1)
}

  /$1/ \{..........

I would like for the customer to enter name or whatever and use that input as the search pattern. The printf displays the input entered correctly - but $1 value is not being used. How do I correctly specify the $1 value to be used as the search argument?

I am only using awk or nawk.

Something like this?

getline var < "-"
printf(">>>>> %s", var)

$0 ~ var {...}

It seems to work except that the $0 ~ var statememt appears to be finding lines with everthing that is in var. From the terminal 'will' is entered.
The lines returned are ones which contain a w or i or l or l. I need it to find lines that only contain will. I really would like it to search like this $0 ~ \<var\>.

Thanks

It should work, this is what I get with this example:

$ cat file
will 123
lliw 456
wil l
$ 
$ awk 'BEGIN{printf("Enter the pattern: ");getline var < "-"}
$0 ~ var {print "The line contains: " $0}' file
Enter the pattern: will
The line contains: will 123
$ 
1 Like