- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can you pass vatiables to 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
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
тАО10-13-2004 09:26 AM
тАО10-13-2004 09:26 AM
Can you pass vatiables to awk?
server=jamie
awk '{if ($2 = $server).....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:30 AM
тАО10-13-2004 09:30 AM
Re: Can you pass vatiables to awk?
Yes. You will have use -v flag with awk to pass them. For ex.,
string="Sridhar"
echo "test" |awk -v name=$string '{print name}'
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:33 AM
тАО10-13-2004 09:33 AM
Re: Can you pass vatiables to awk?
awk '{if ($2 = "'$server'"...
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:40 AM
тАО10-13-2004 09:40 AM
Re: Can you pass vatiables to awk?
server=jamie
awk -v server=$server '{if ($2 = $server)...
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:47 AM
тАО10-13-2004 09:47 AM
Re: Can you pass vatiables to awk?
Instead of the string 'jamie' I get:
if $2 = server
I tried it with $server and "$server" but it doesn't work...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:50 AM
тАО10-13-2004 09:50 AM
Re: Can you pass vatiables to awk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:56 AM
тАО10-13-2004 09:56 AM
Re: Can you pass vatiables to awk?
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 09:57 AM
тАО10-13-2004 09:57 AM
Re: Can you pass vatiables to awk?
echo "jamie" | awk '{ if ( $1 == server ) print "ok" }' server=jamie
It will pass that environment variable of server with jamie string there.
You can more check as,
echo "hai" | awk '{ print server }' server=jamie
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 10:01 AM
тАО10-13-2004 10:01 AM
Re: Can you pass vatiables to awk?
server_time="07:08:55"
awk -v time=$server_time {if ($9 < time && $10 > time)
when I debug it looks like this:
awk -v time=07:08:55 {if ($9 < time && $10 > time)
shouldn't the time be replaced with the value of the time variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 10:08 AM
тАО10-13-2004 10:08 AM
Re: Can you pass vatiables to awk?
It is as,
echo "hai jamie" | awk --assign server=jamie '{ if ( $1 == server ) print "OK" }'
Else try awk -v
see man awk.
HTH.