- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk and assigning values to multiple variables
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
тАО12-21-2004 12:37 AM
тАО12-21-2004 12:37 AM
My file has one line from TOP
0 ? 37 root 152 20 0K 1888K run 247:32 0.58 0.58 vxfsd
All I want to do is assign each piece of this line to a seperate variable. I could do
awk'{print $1" "$2 " "$3}' toptest.txt | while read var1 var2 var3; do
do whatever
done
but I would like to stay away from the loop since there is (and will only be) one line of data
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 12:45 AM
тАО12-21-2004 12:45 AM
Re: Awk and assigning values to multiple variables
var2=$(awk'{print $2}' toptest.txt)
var3=$(awk'{print $3}' toptest.txt)
This should populate the variables without using a loop.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 12:47 AM
тАО12-21-2004 12:47 AM
Re: Awk and assigning values to multiple variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:30 AM
тАО12-21-2004 01:30 AM
Re: Awk and assigning values to multiple variables
the simplest way with just using the shell, would be:
cat file | read var1 var2 var3 rest
print "$var1 $var2 $var3" #just to test
and if you don't mind reading from right to left:
read var1 var2 var3 rest < yourfile
- Tags:
- redirect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:32 AM
тАО12-21-2004 01:32 AM
Re: Awk and assigning values to multiple variables
cat file | while read v1 v2 v3 ... v13
do
commands
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:40 AM
тАО12-21-2004 01:40 AM
Re: Awk and assigning values to multiple variables
set -A array $(
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:49 AM
тАО12-21-2004 01:49 AM
Re: Awk and assigning values to multiple variables
set -- $(yourfile)
print $1 $2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 01:52 AM
тАО12-21-2004 01:52 AM
Re: Awk and assigning values to multiple variables
should have been
set -- $(
print $1 $2
forgot the < in $(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-21-2004 02:01 AM
тАО12-21-2004 02:01 AM
Re: Awk and assigning values to multiple variables
read var1 var2 var3 < toptest.txt
method.
Thanks for all the input!!
Scott