- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script variables within awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:23 AM
12-22-2003 03:23 AM
I use variables within a script and I would like to use them within an awk command without the -v option.
For example:
THRESHOLD1=90
THRESHOLD2=95
bdf | awk '{print $1, ":$THRESHOLD1:$THRESHOLD2"}' > FILE
I know this would work:
bdf | awk -v thr1=$THRESHOLD1 -v thr2=$THRESHOLD2 '{print $1, ":thr1:thr2"}' > FILE
but I am looking for something... smarter.
Can someone help me?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:32 AM
12-22-2003 03:32 AM
Re: script variables within awk
This is helpful if the number of variables to ber passed is not known
Alternatively you can string these variables together to pass only 1 variable to the awk statement!
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:34 AM
12-22-2003 03:34 AM
Re: script variables within awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:42 AM
12-22-2003 03:42 AM
Re: script variables within awk
bdf | perl -nae 'print "$F[0]:$ENV{THRESHOLD1}:$ENV{THRESHOLD2}' >FILE
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:45 AM
12-22-2003 03:45 AM
Re: script variables within awk
if it is a newer version, such as on an 11i system, you can use the ENVIRON array to access the values
export THRESHOLD1=90
export THRESHOLD2=95
bdf | awk '{print "$1, :ENVIRON[THRESHOLD1]:ENVIRON[THRESHOLD2]";}' > FILE
and of course you can also pass values to awk using the command line via argc and argv somewhat like a c program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:48 AM
12-22-2003 03:48 AM
Re: script variables within awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 03:49 AM
12-22-2003 03:49 AM
Re: script variables within awk
ENVIRON["THRESHOLD1"]
and you don't have to export the variables;
export THRESHOLD1=90
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 07:47 AM
12-22-2003 07:47 AM
Re: script variables within awk
believe Curt, environ is what you need to evaluate envoronment variables from within awk. See man awk.
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 08:13 PM
12-22-2003 08:13 PM
Re: script variables within awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 08:19 PM
12-22-2003 08:19 PM
Re: script variables within awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 08:31 PM
12-22-2003 08:31 PM
Re: script variables within awk
can you post an example and why it does not work, i mean any error messages?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 09:00 PM
12-22-2003 09:00 PM
Re: script variables within awk
Nevertheless, you can run something like :
(echo 90 && echo 95 && bdf) |
awk 'BEGIN{getline; th1=$0; getline; th2=$0; }
{print $1,th1,th2;}'
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 09:23 PM
12-22-2003 09:23 PM
Re: script variables within awk
there is an alternativ to environ. Store the values of the environment variables into a file and then read them ony by one.
getline < extvarfile; var1=$0;
getline < extvarfile; var2=$0;
greetings
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2003 10:03 PM
12-22-2003 10:03 PM
Re: script variables within awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 12:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2003 03:34 AM
12-23-2003 03:34 AM
Re: script variables within awk
THRESHOLD1=90
THRESHOLD2=95
bdf | awk '{print $1, ":"THRESHOLD1":"THRESHOLD2}' THRESHOLD1=$THRESHOLD1 THRESHOLD2=$THRESHOLD2 > FILE
or
bdf | awk '{print $1, ":"THRESHOLD1":"THRESHOLD2}' THRESHOLD1=90 THRESHOLD2=95 > FILE
Rory