Programming

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

How to call a variable in awk again ?


👤 Login to reply

    #1  
Old 05-17-2017
Zabo Zabo is offline
Registered User
 
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)

Code:
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 :
Code:
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

Last edited by Corona688; 05-17-2017 at 04:12 PM..
Sponsored Links
    #2  
Old 05-17-2017
RavinderSingh13 RavinderSingh13 is offline Forum Advisor  
Registered User
 
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.
Code:
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.
Code:
./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
Sponsored Links
    #3  
Old 05-17-2017
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
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.

Code:
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
Ethan Stark Ethan Stark is offline
Registered User
 
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

Code:
awk '{
    cmd = "your_command " $1
    while (cmd | getline line) {
        do_something_with(line) 
    }
    close(cmd)
}' 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
Sponsored Links
👤 Login to reply

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 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
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 01:46 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?