Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get input from both file and the terminal? I wish to ask the user something in the END portion of the awk script.

That input should be typed in by the user and not read from the file which had the data to be processed.

  getline choice
  if(choice == "Y")
    print "OK"

But choice is read off the input file.

share|improve this question
awk was not really designed for interactive use. You can pass choice directly to awk like awk -f script.awk -v choice=Y, and use a wrapper shell script to do the interactive part. If you really need to wait until the END block to ask for choice, you could try getline < "/dev/tty" as a not terribly portable workaround. – jw013 Nov 12 '12 at 15:58
up vote 4 down vote accepted

You can read from /dev/tty or from /dev/stdin.

getline choice < "/dev/tty"

/dev/tty is pretty ubiquitous (even one the very few, along with /dev/null and /dev/console to be required by POSIX), /dev/stdin is less common, but at least GNU awk would recognize it as meaning stdin even if the system doesn't have such a device/special file.

share|improve this answer

As can be seen, - also works:

getline < "-"


getline variable < "-"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.