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 ?

Programming


Tags
awk, linux, unix

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
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)


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 05:12 PM..
Sponsored Links
    #2  
Old Unix and Linux 05-17-2017   -   Original Discussion by Zabo
RavinderSingh13's Unix or Linux Image
RavinderSingh13 RavinderSingh13 is online now Forum Advisor  
Registered User
 
Join Date: May 2013
Last Activity: 18 December 2017, 1:54 AM EST
Location: Chennai
Posts: 2,681
Thanks: 590
Thanked 1,276 Times in 1,147 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.

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 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: 14 December 2017, 4:58 PM EST
Location: Saskatchewan
Posts: 22,547
Thanks: 1,159
Thanked 4,287 Times in 3,955 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.


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 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
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 09:32 AM.. Reason: code tags
Sponsored Links
Closed

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 12:07 PM
Variable names within array call vockleya Shell Programming and Scripting 2 01-22-2009 10:03 PM
Bash: how to call function having it's name in variable? FractalizeR Shell Programming and Scripting 4 08-24-2008 11:27 AM
Enviornment Variable in B shell (I call it nested variable) princelinux Shell Programming and Scripting 4 07-02-2008 02:35 AM
does this variable call work--Korn morkfard UNIX for Dummies Questions & Answers 2 07-10-2001 11:59 AM



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