How to call a variable in awk again ?

Hi again and thanks to R.Singh.

One more question here.

The code works in awk. (or GAWK)

awk 'BEGIN{print "Enter your Name: ";getline name < "-";print RS "Input entered by user is: "name}'

How to display the variable name again ?

The awk script is running automaticly to the end.

I have tied :

echo  $name
                     awk ' {print "name"} '

Seems that the variable is gone from the memory.

DURING a program execution they stay. However.

But how to hold the program in interpreted modus ?

awk is interpreted i think . anyway it ends the script automaticly in the CMD terminal from Linux.

Any suggestions or ideas about that ?

WBR
Zabo

Hello Zabo,

Not sure why there is a necessity for using awk ? You could use shell's built-in command called read to take Input from user, following is an example for same too.

cat script.ksh 
echo "enter a variable please:"
read variable
echo "I am printing variable here......."
echo $variable

So while running the above script following output will come.

./script.ksh 
enter a variable please:
R. Singh
I am printing variable here.......
R. Singh

I hope this helps you, kindly do let me know if you have any queries on same.

Thanks,
R. Singh

code tags for code, please.

awk is awk, shell is shell. If you don't output the value in awk, it won't get put out.

VAR=$(awk '{ ... }' )

For interactive programs, you should be printing prompts and such to > "/dev/stderr", so they won't end up in VAR.

Or you could write the whole program in awk, or at least do a large amount of processing in awk, so there's less need for transfer.

27
down vote
You cannot grab the output of an awk system() call, you can only get the exit status. Use the getline/pipe or getline/variable/pipe constructs

awk '{
    cmd = "your_command " $1
    while (cmd | getline line) {
        do_something_with(line) 
    }
    close(cmd)
}' file

Ethan Stark