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

AWK "Pause/Enter Data" Function?

Status
Not open for further replies.

calabrra

Technical User
Sep 16, 2003
14
US
Hi,

I'm running AWK from DOS on Win2000. Is there a function that allows user to pause and enter parameter data?


Thanks,
-Bob
 
Use

getline var1 < &quot;-&quot;

to read data from the user and save it in variable var1.

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
I assume you mean gawk?
If so use getline.

Code:
function parray(arrnme,ind, i) {
i=0

         while (i < ind) {print arrnme[i]; i++}
}  
        
BEGIN {
srand()
val = 0

       while (x < int(1 + rand() * 12)) {
              printf &quot;%s:&quot;, &quot;Enter your value&quot;
              getline val < &quot;-&quot;
              if (!val) {print &quot;No value entered..quitting ; exit}
              printf &quot;\n%s: %d\n&quot;, &quot;You entered&quot;,val
              arr[x] = val
              ++x
       }
parray(arr,x)
}
 
Hmmm...

I tried these commands (i.e. print / getline) but GETLINE doesn't show up on the DOS window...and it seems like the PRINT output is being written to a file that is already open.

This is what I have in the BEGIN section:

print &quot;%s:&quot;, &quot;Want to continue? (1/0)...&quot; ;
getline varexit < &quot;-&quot; ;
if (varexit == 0) exit;

Is there special syntax to send/receive info to/from the DOS console window?

I'm using &quot;awk95.exe&quot; to interpret the source code. I assume it is GAWK.


Thanks,
-Bob
 
Seems that your awk95 is called within a script with redirection. Have you tried somethng like this ?
Code:
  print &quot;Want to continue? (1/0)...&quot; >&quot;CON:&quot;;
  getline varexit < &quot;CON:&quot;;
  if (varexit == 0) exit;

Hope This Help
PH.
 
If you want to print instructions for the user to the screen you can print your data to a named file, instead of stdout. Something like this.

awk -v fn=&quot;tst.dat&quot; -f std.awk std.awk

BEGIN {
if (!fn) fn=&quot;std.out&quot;
}
{
print > fn
print &quot;Continue: (y/n)...&quot;
getline varexit < &quot;-&quot;
if (varexit ~ /^[nN]/) exit
}

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
The second std.awk on the command line should be your input file

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top