- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Newbie Array Question
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
тАО09-07-2004 03:04 AM
тАО09-07-2004 03:04 AM
cat /tmp/thrdsts.txt | while line=`line`
do
thread=`echo $line | awk '{print $1}'`
status=`echo $line | awk '{print $2}'`
done
I'm hoping this will get the assigning part done(am I right?). Next question is how do I reference these. I've trien echo $thread[1], but all I get is [1].
I'm using what I think is bourne shell /bin/sh, on HP-UX 11.0
Thanks
Scott
Solved! Go to Solution.
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:20 AM
тАО09-07-2004 03:20 AM
Re: Newbie Array Question
The standard HP-UX Bourne Shell is a Posix shell (see "man sh-posix", especially the section on arrays)
Initilisation and value assignment can take place in the same line.
e.g.
# set -A array tic tac toe
# echo ${array[*]}
tic tac toe
or you can assign elements individually
e.g.
# array[${#array[*]}]=donald
# echo ${array[*]}
tic tac toe donald
n.b. just insert the correct index in the square brackets, the ${#array[*]} construct derefernces the dimension of the array, thus the right index for the next element
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:21 AM
тАО09-07-2004 03:21 AM
SolutionOne way to do it in the POSIX shell is like this:
set -A thread $(awk '{print $1} /tmp/thrdsts.txt)
set -A status $(awk '{print $2} /tmp/thrdsts.txt)
echo "thread[1] is ${thread[1]}"
You can use the 'set -A' like above to declare your variable as an array and set the elements of the array to the list provided by the next argument.
In the POSIX shell you are limited to 1024 elements in your array, so if you have a large file you might want to consider using something like Perl.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:22 AM
тАО09-07-2004 03:22 AM
Re: Newbie Array Question
cat /tmp/thrdsts.txt | while line=`line`
do
thread_$CNT=`echo $line | awk '{print $1}'`
status_$CNT=`echo $line | awk '{print $2}'`
CNT=`expr $CNT + 1`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:23 AM
тАО09-07-2004 03:23 AM
Re: Newbie Array Question
# i=0; while [ $i -lt ${#array[*]} ];do echo ${array[$i]};((i+=1));done
tic
tac
toe
donald
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:26 AM
тАО09-07-2004 03:26 AM
Re: Newbie Array Question
let count=1
cat /tmp/thrdsts.txt | while line=`line`
do
thread[$i]=`echo $line | awk '{print $1}'`
status[$i]=`echo $line | awk '{print $2}'`
let i=i+1
done
then you will refer to arrays with :
${thread[$n]}
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:34 AM
тАО09-07-2004 03:34 AM
Re: Newbie Array Question
set -A thread $(awk '{print $1}' /tmp/thrdsts.txt)
set -A status $(awk '{print $2}' /tmp/thrdsts.txt)
I like it because there is no need for a while.
Thanks to all who replied.