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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I input from keyboard in awk 2

Status
Not open for further replies.

obtuse

Instructor
Jan 8, 2002
2
US
I need to input data from the keyboard in awk.The only
reference I can find in any of my AWK books is
to do the following:

BEGIN { printf "Enter your name: "
getline name < &quot;-&quot;
print name
}

This was accompanied by the footnote that not all
versions of awk/nawk/gawk/etc. support the use of
&quot;-&quot; with getline to read from the standard input.
I am using UNIX on a Sun system, and < &quot;-&quot; does
not work.

I tried using the following:

printf &quot;Enter your name: &quot;
system(&quot;read&quot;) | getline name

This stops program flow and allows you to type in
data, but I cannot get the inputted data into an
awk variable, in this case name.
Any ideas?
 
I run Solaris 2.6, it does not work with awk but ir does with nawk.

nawk 'BEGIN { printf &quot;Enter your name: &quot;
getline name < &quot;-&quot;
print name
}' [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
 

I am the originator of this thread.
I finally got hold of a UNIX guru I know
and he suggested the following.
It seems to work with most versions
of awk nawk gawk, etc.

printf &quot;Enter your name: &quot;
system(&quot;read a; echo $a&quot;) | getline name
print name

I hope this may help someone else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top