Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-04-2007
Registered User
 

Join Date: Jul 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Global Variable in awk...

i think.....

it's possible use a variable out a awk in the awk ???

ex.

A=20071225

awk '{ print "the value is" $a }'
OR
awk '{ print "........"; c=10; print $c ; c=$A ; print $A}'

for a external variable is possbile use in the awk ???
Sponsored Links
    #2  
Old 07-04-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 60 Times in 56 Posts
You can do :

Code:
A=20071225
awk '{ print "the value of A is" '"$A"' }' infile

Or

Code:
A=20071225
awk -v A="$A" '{ print "........"; c=10; print $c ; c=A ; print A}' infile

or

Code:
A=20071225
awk  '{ print "........"; c=10; print $c ; c=A ; print A}' A="$A" infile

or

Code:
export A=20071225
awk '{ c=ENVIRON["A"] + $1; print c}' infile

Sponsored Links
Closed 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
global variable not being set robotball Shell Programming and Scripting 5 06-10-2008 06:20 AM
global variable in awk anhtt Shell Programming and Scripting 1 03-16-2008 02:55 PM
setting a global variable in script arunkumar_mca UNIX for Dummies Questions & Answers 3 10-23-2007 07:46 AM
Global Variable in a script? skyineyes Shell Programming and Scripting 2 07-12-2007 06:55 AM
Global variable becomes local odashe318 Shell Programming and Scripting 2 10-29-2004 09:18 PM



All times are GMT -4. The time now is 05:07 AM.