awk - input function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - input function
# 1  
Old 06-02-2006
awk - input function

hello,

im a newbie. how can i input data from keyboard? thanks.
# 2  
Old 06-02-2006
Ex:
Code:
function getName (NOM)
{
printf "Enter a filename: "
getline NOM < "/dev/tty"
close("/dev/tty")
return NOM
}

BEGIN {
printf ("\nREP: %s\n",getName(N)) 
} 
{print}

# 3  
Old 06-02-2006
Thank you again klash. I thought in that after posting but really dont like getline, just for curiosity is there other way?

thx.
# 4  
Old 06-02-2006
a slightly different approach, but still using 'getline':
Code:
  cmd="read line;echo ${line}"
  cmd | getline line
  close(cmd);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

Passing Oracle function as file input to sqlplus

Apologies if this is the incorrect forum.There is an issue in the function call I am facing while calling the same from a unix shell scripts. Basically, I want the ref cursor to return values to a variable in sqlpus. The function call is currently saved in a ".txt" file in a unix location. I want... (7 Replies)
Discussion started by: amvip
7 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

Passing Input To Function

May i please know why is it printing the script name for $0 when i pass those parameters to function. #!/bin/bash -x usage() { echo "In Usage Function" echo $0 echo $1 echo $2 } echo "printing first time" echo $0 echo $1 echo $2 usage $0 $1 $2 Output: (2 Replies)
Discussion started by: Ariean
2 Replies

5. Homework & Coursework Questions

Function to Check if string input from user is alphabetic only

Good Evening. I'm new to C. Can you please help me. I'm creating an error checking function, user will input a string, this will check if the input is all alphabet or all letters only. If there is a digit or other special char, it will print Error then ask input from user again. Here's my... (1 Reply)
Discussion started by: eracav
1 Replies

6. UNIX for Dummies Questions & Answers

apply a function twice successively with the same input in awk program

Hi ! It is a general question. When an awk script looks like: #! bin/awk function example(i){ <body> } { example(1) #the function uses input_1 and return output_a } { example(2) #the function uses previous output_a as an input and returns... (15 Replies)
Discussion started by: beca123456
15 Replies

7. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

8. Shell Programming and Scripting

function from shell input

Hi all i have the command called printer which needs a usernmae for example i would run the commnad printer <username> how can i write i quick script in perl that if the username is ab then write "denined" and if it is anything else it will work thanks Adam (1 Reply)
Discussion started by: ab52
1 Replies

9. Shell Programming and Scripting

Split function input and output order

Dear Forum I'm Trying to use split function to split a string, but the output is not as the same order as of the string, please see simple example echo " " | nawk -v var="First;Second;Third;Fourth" ' BEGIN {split(var, arr,";") for(i in arr){print arr }}' The output is Second Third... (6 Replies)
Discussion started by: yahyaaa
6 Replies

10. UNIX for Advanced & Expert Users

conversion of a input function to i18n

m using unix c with curses im trying out the conversion of an existing code in c to i18n for the japanese language. the problem is that, the input which is given as the japanese characters is not taken correctly. and what it outputs is question marks(i.e. ???), equivalent to the number o f... (4 Replies)
Discussion started by: nirnay_s
4 Replies
Login or Register to Ask a Question