Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getline problem 1

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
hi,


could somebody tell what is wrong with this command

awk 'BEGIN {"read c" | getline vc close("read c"); print vc}'


the idea is to read in some variable from STDIN and to use it in awk commands


thanks
oliver
 
Hi

If the executed command does not have an output, the [tt]getline[/tt] has nothing to read. The [tt]read[/tt] shell function has no output.
Code:
awk 'BEGIN {"read c[red]; echo $c[/red]" | getline vc[red];[red] close("read c"); print vc}'

Feherke.
 
This is the technique I have used in the past to request user input in an awk script:

[tt]awk -v TTY=`tty` 'BEGIN { getline < TTY ; print "you entered " $0 }'[/tt]

Annihilannic.
 
With unix you may try this:
awk '
BEGIN{t="/dev/tty";printf "Value of c ? ">t;getline<t;vc=$1;print vc}
'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top