Home Man
Today's Posts

Post questions about C, C++, Java, SQL, and other programming languages here.

How to call a variable in awk again ?

awk, linux, programming, unix

Login to Reply

Thread Tools Search this Thread
# 1  
Old 05-17-2017
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 ?


Last edited by Corona688; 05-17-2017 at 04:12 PM..
# 2  
Old 05-17-2017
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.
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.

R. Singh
# 3  
Old 05-17-2017
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.
# 4  
Old 06-13-2017
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) {
}' file

Moderator's Comments:
How to call a variable in awk again ? please use code tags

Ethan Stark

Last edited by jim mcnamara; 06-13-2017 at 08:32 AM.. Reason: code tags
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to call variable inside a function globally? ernesto UNIX for Beginners Questions & Answers 2 01-16-2017 11:52 AM
Dereferencing variable inside egrep call aoussenko Shell Programming and Scripting 1 01-23-2015 11:36 AM
Call a awk script with variable and input filename Onkar Banerjee Shell Programming and Scripting 0 04-19-2013 03:55 AM
Passing awk variable in perl -e call pedro6994 Shell Programming and Scripting 0 03-21-2011 11:18 AM
How to call arguments with variable in a script?? VanK Shell Programming and Scripting 4 05-06-2010 11:07 AM
Variable names within array call vockleya Shell Programming and Scripting 2 01-22-2009 09:03 PM
Bash: how to call function having it's name in variable? FractalizeR Shell Programming and Scripting 4 08-24-2008 10:27 AM
Setting environment variable using JNI call shafi2all Programming 6 07-18-2008 12:23 PM
Enviornment Variable in B shell (I call it nested variable) princelinux Shell Programming and Scripting 4 07-02-2008 01:35 AM
does this variable call work--Korn morkfard UNIX for Dummies Questions & Answers 2 07-10-2001 10:59 AM

All times are GMT -4. The time now is 06:13 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password