The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing values into logrotate?? imbiea Shell Programming and Scripting 1 06-09-2008 04:03 PM
passing variable values to awk command jerardfjay Shell Programming and Scripting 1 05-22-2008 03:48 PM
passing values from sql to shell script sachin.gangadha Shell Programming and Scripting 3 04-22-2008 11:11 PM
Passing Values from a shell script dhananjaysk Shell Programming and Scripting 6 04-06-2006 09:33 AM
Passing values from SQR to UNIX seeuinoz UNIX for Advanced & Expert Users 2 08-24-2005 03:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2003
gio123bg gio123bg is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 15
Question Passing values out awk.

found that passing (input) values to awk, all work well. For example:
errpt | awk 'BEGIN { errore=0 }
substr($2,1,4) /'ParamData'/ {
....
} ' ParamData=`date +"%m%d"`

Now I wish to obtain (output) a value. Using this method is it possible to re-write ParamData, for example?

Thanks in advance for your kind cooperation.
Regards.

Giovanni
  #2 (permalink)  
Old 11-28-2003
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
You can print the value in awk and read it into your script, e.g...

$ echo 1 | awk '{print $1 + p}' p=2 | read p
$ echo $p
3
  #3 (permalink)  
Old 12-09-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Ygor,
Over the past week or so I have had to write a couple of awk scripts and have really begun to see how powerful it can be. However, awk is still a bit foreign to me, can you elaborate on this syntax for me? What confuses me is the fact that p=2 is outside of the ending quote for the awk peice. How is the value of 2 available to awk?

echo 1 | awk '{print $1 + p}' p=2 | read p
  #4 (permalink)  
Old 12-09-2003
tikual tikual is offline
Registered User
  
 

Join Date: Nov 2003
Location: HK
Posts: 53
Ygor really a expert in awk!! I viewed his posts and I still need to learn from him/her.

I know that is one of method to set variable in awk.

And I know 3 methods to do that, maybe more than 3 ways then I may not know.
Method 1:
Variable was assigned after any actions, var cannot be read in BEGIN {} because action in BEGIN {} is started before reading the script.
awk '{print $0}' var=$1 filename

Method 2:
One variable with one -v, variable can be read in BEGIN{} and the script.
awk -v var1=$1 -v var2=$2 '{print $0}' filename

Method 3:
assign variable in the script body.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0