awk user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk user input
# 1  
Old 10-29-2007
Question awk user input

Using the following I'm trying to print the user's response to the prompt Y / N but I get nothing other than the contents of $1?

awk '{
printf($1 " ? (Y/N)")
getline myresponse < "-"
system("read myresponse")
if (myresponse == "Y")
{ print $1 myfrans }
}' $myfile
# 2  
Old 10-29-2007
Code:
nawk '
  BEGIN {
     printf "Enter your name: "
     getline name < "-"
     print name
}' < /dev/null

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 10-29-2007
Quote:
Originally Posted by vgersh99
Code:
nawk '
  BEGIN {
     printf "Enter your name: "
     getline name < "-"
     print name
}' < /dev/null

Thanks for the reply but this does not work, I need awk (or nawk) to read a file that contains lines, the user is then shown the line and should enter Y to select it or N to skip. If they select Y it should be written into another file or variable for use later in the script.
# 4  
Old 10-29-2007
nawk -f gefa.awk myInputFile

gefa.awk:
Code:
function promptMe(myLine,   yn)
{
   printf("Select [%s] (Y/N): ", myLine)
   getline yn < "-"

   return tolower(yn)
}
{
  if (promptMe($0) == "y")
     print "do the YES thingy"
  else
     print "do the NO thingy"
}

# 5  
Old 10-29-2007
Thanks, that is better, but still having problems as it displays all lines from myInputFile without prompting. With system("read") I get the prompts but input is ignored?

Quote:
Originally Posted by vgersh99
nawk -f gefa.awk myInputFile

gefa.awk:
Code:
function promptMe(myLine,   yn)
{
   printf("Select [%s] (Y/N): ", myLine)
   getline yn < "-"

   return tolower(yn)
}
{
  if (promptMe($0) == "y")
     print "do the YES thingy"
  else
     print "do the NO thingy"
}

# 6  
Old 10-29-2007
Works fines under Solaris 9 "nawk".
# 7  
Old 10-29-2007
I'm using AIX5.2

Quote:
Originally Posted by vgersh99
Works fines under Solaris 9 "nawk".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to search based on 5 user input fields

Field1=”” Field2=”” Field3=”” Field4=”” Field5=”” USER INPUT UP TO 5 FIELDS awk -F , '{ if ( $3 == Field1 && $6 == Field2 && $8 == Field3 && $9 == Field4 && $10 == Field5) print $0 }' /tmp/rodney.outD INPUT FILE (Rodney.outD): ... (3 Replies)
Discussion started by: rmerrird
3 Replies

2. Programming

Keyboard User Input in awk language ?

Hi, does someone know how to make a keyboard data input in the AWK programming language ? Regards Zabo (6 Replies)
Discussion started by: Zabo
6 Replies

3. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

4. UNIX for Dummies Questions & Answers

Clumsy user input

The (longer) script that I am working on does something like this: #!/bin/bash while true do clear sleep 1 shuf -i1-2 -n1 sleep .1 clear echo "Press 1 if you saw a 1. Press 2 if you saw a 2." read -s -n1 RESPONSE done If the user accidentally presses two... (1 Reply)
Discussion started by: darwin_886
1 Replies

5. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

6. Shell Programming and Scripting

Awk replacing file with user input

this section of the awk code i have here takes file to work with from the user. the user specifies the file name from the command line and the file name is assigned to the variable $FLIST awk 'BEGIN { while((getline < "'${FLIST}'")>0) S FS="\n"; RS="}\n" } now, i dont want... (5 Replies)
Discussion started by: SkySmart
5 Replies

7. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

8. Shell Programming and Scripting

How to take input from user or awk script?

Hi Jim, I have following script,i which i need to take dynamic value . script, nawk -v v1=grep"INT_EUR" $propertifilename | cut -d"=" -F2` -F'~' '{if (NF-1 !=v1) {print "Error in " $0 " at line number "NR" tilde count " N-1}}' $filename In the above script i want to use INT_EUR as a variable... (2 Replies)
Discussion started by: Ganesh Khandare
2 Replies

9. Shell Programming and Scripting

AWK set FILENAME via user input

I am trying to write a awk script that prompts user for input to set the FILENAME varable. I can get it set, but I think awk is not doing anything with it. this is what I have so far #!/usr/bin/nawk -f BEGIN { FILENAME = "" printf "Enter name of file to check in : " ... (2 Replies)
Discussion started by: timj123
2 Replies

10. Shell Programming and Scripting

Getting user input

I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.... (3 Replies)
Discussion started by: stevefox
3 Replies
Login or Register to Ask a Question