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
Discussions
Discussions
Forums
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
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
тАО02-19-2002 01:43 AM
тАО02-19-2002 01:43 AM
AWK
I have one query in AWK..
I am trying to assign some value to a variable and then trying to access that variable out of awk..
But then I could not succeed in doing that..
Say for ex
$ echo "one two" | awk '{var=$1}'
$ echo "$var"
I would like to use the value of variable "VAR" out of awk.
Is there any way to do it ?
I checked the awk documentation as well..
But then could not find what I want..
So..Can any one pls give me some input on this issue ?
Thanks
Sundar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 01:49 AM
тАО02-19-2002 01:49 AM
Re: AWK
Maybe try :
export var=`echo "one two" | awk '{print $1}'
echo $var then shows 'one'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 01:50 AM
тАО02-19-2002 01:50 AM
Re: AWK
first you have to give variables to AWK when using the -v option
awk -v var=value
you can now use the variable in awk- programs.
And you have the possibility to put the output of awk into a variable using command substitution:
var=`cat file |awk '{print $5}'`
after this "trick", you can use var in your scripts.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 01:54 AM
тАО02-19-2002 01:54 AM
Re: AWK
there is a little typo in Corthouts Carlos script, he forgot to close the backticks for the command substitution.
Additional:
when using a ksh or a POSIX shell you can also use the following syntax:
var=$(command1 | command2 | command3)
this is bad if you use a Bourne shell, which doesn't know this.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 02:11 AM
тАО02-19-2002 02:11 AM
Re: AWK
# a=fred
# echo hello | awk '{print $0,var}' var=$a
hello fred
should do it for you.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 06:53 AM
тАО02-19-2002 06:53 AM
Re: AWK
I know there are two possible ways to take out the value from AWK to a variable
$ var="Value"
$ awk -v a=$var '{print a}' /tmp/somefile
But then that is not what I am trying to do..
We can only pass down the values from Shell to AWK ..
I am looking out for a way to pass down the value from AWK to SHELL..i.e I will assign some value to a variable inside AWK and then I would like to refer that Variable out of AWK in the SHELL...
and when it comes to assigning variable a value like this
$ var=$(awk '{inst}' files)
I beleive We can assign value to only one variable..
But I am looking to assign value to MORE THAN one VARIABLE..and then refer that variable out of AWK..
Hope and wish I am clear and pls let me have some inputs on these things
Thanks
Sundar
Sundarhp@hotmail.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 07:03 AM
тАО02-19-2002 07:03 AM
Re: AWK
awk { ..... } | read var1 var2 var2
You can get the idea by doing something like this:
echo "XX" "YY" "ZZ" | read var1 var2 var3
$var1 -> XX
$var2 -> YY
$var3 -> ZZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2002 07:11 AM
тАО02-19-2002 07:11 AM
Re: AWK
of course you can read several variables the way described by Clay. Or you can redirect the output of the awk- command into a file:
awk '{action}' file > "file_name"
and work with the file after that....
Allways stay on the bright side of life!
Peter