Unix/Linux Go Back    

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

How to call a variable in awk again ?


awk, linux, unix

Thread Tools Search this Thread Display Modes
Old Unix and Linux 05-17-2017   -   Original Discussion by Zabo
Zabo's Unix or Linux Image
Zabo Zabo is offline
Registered User
Join Date: Dec 2016
Last Activity: 15 June 2017, 4:56 PM EDT
Location: Germany
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
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..
Sponsored Links
Old Unix and Linux 05-17-2017   -   Original Discussion by Zabo
RavinderSingh13's Unix or Linux Image
RavinderSingh13 RavinderSingh13 is offline Forum Advisor  
Registered User
Join Date: May 2013
Last Activity: 23 March 2018, 12:02 AM EDT
Location: Chennai
Posts: 2,704
Thanks: 603
Thanked 1,289 Times in 1,158 Posts
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
Sponsored Links
Old Unix and Linux 05-17-2017   -   Original Discussion by Zabo
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 22 March 2018, 2:04 PM EDT
Location: Saskatchewan
Posts: 22,620
Thanks: 1,171
Thanked 4,303 Times in 3,969 Posts
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.
Old Unix and Linux 06-13-2017   -   Original Discussion by Zabo
Ethan Stark's Unix or Linux Image
Ethan Stark Ethan Stark is offline
Registered User
Join Date: Jun 2017
Last Activity: 14 June 2017, 4:26 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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:30 AM.