- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2004 10:23 AM
10-13-2004 10:23 AM
Re: Can you pass vatiables to awk?
Your time variable should get passed correctly but your 'test' conditions may produce unexpected results as the time variable is treated as 'text' and using <,> operators on it may not give what you expect.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2004 10:26 AM
10-13-2004 10:26 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 10:31 AM
10-13-2004 10:31 AM
Re: Can you pass vatiables to awk?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2004 10:34 AM
10-13-2004 10:34 AM
Re: Can you pass vatiables to awk?
Started to play with awk right now. If you get your problem solved, treat responders with points to get more informations in near future and get good interaction.
Best wishes.
Muthukumar.