I need help in creating a array in shell scirpt.
I have a file which has following details.
Above is my test file. I need to create a array in which should be following format.
all the 4 digit values 1234,2343,2353,3343,3435,2343 belong to same host until the next host name in the starting of the line.EG in my eg file abcdmhs10,bcdfmhs11 are the host names and
1234,2343,2353,3343,3435,2343 are the luns that this host has been assigned.
It is not that host name are just [a-zA-Z] they may contain "_" as well.
Now I want to create a file or data structure such a way that i should be able to access all the devices assigned to host.
I am trying with array's in awk. I couldn't exactly figure host to get the all the devices in one line.
Please help me out. Thanks in advance.
Last edited by Franklin52; 06-24-2011 at 03:28 AM..
Reason: Please use code tags for code and data samples, thank you
Associative arrays are supported in some shells: ksh93, bash >=4.0, zsh
I am sorry , I am new to awk programming. I didn't understand what you are doing in the script using associative arrays. Can you write it in bash with comments, it will really help me. I actucally need to perform some other operation with this data.
I need to find out the sizes of each lun for each host.
hostname devices FA0 size
device FA07C:1 69053
device FA07C:1 34536
device FA07C:1 34526
abcdmhs10 1234 FA08C:0 69053
2343 FA08C:0 34536
2353 FA08C:0 34526
3343 FA08C:0 69053
3435 FA08C:0 34536
2343 FA08C:0 34526
bcdfmhs11 2343 FA09A:1 69053
2443 FA09A:1 34536
3434 FA09A:1 34526
8874 FA09A:1 69053
0343 FA09A:1 34536
3434 FA09A:1 34526
efghnhy001 1234 FA06B:0 69053
4687 FA06B:0 34536
5673 FA06B:0 34526
5678 FA06B:0 69053
9857 FA06B:0 34536
3434 FA06B:0 34526
This should be my final o/p.
Now i need to find out the host and all the devices that are masked to that host and size of each device for that host.
i can find out the size of the each lun using some symmetrix command.
but find out each and every lun would take more time i was wondering if I could run one command
symdev -sid aaaa|egrep "1234|2343|2353|3343|3435|2343" will give the lun sizes in $4 column. I need to add that column value to o/p and my final o/p should be in the above format.
Any pointers is greatly appreciated. thanks in advance.
Hello everyone,
First of all this is my first post and im fairly new to working with Unix and creating scripts etc. so there will probably be wrong phrases used.
Lets get to my questions.
I have multiple scripts that submit Slurms/Jobs to the cluster starting like this and doing certain... (3 Replies)
Ok so spaces separate elements. What if you wanted an element to have a space in it?
For instance:
nums="one two three and a half"
where "three and a half" is THE SAME element? (3 Replies)
I have three arrays. One is Master array and that has list of other array in config file.
for e.g (for simplicity I have only defined array with 2 elements each)
set +A MASTERARRAY SQLUPDATE_ONETIME SQLUPDATE_DAILY END_OF_ARRAY
set +A SQLUPDATE_ONETIME update12 update22 END_OF_ARRAY... (4 Replies)
hi guys,
i have the following code in C shell..
set i=0
while ($i < 11)
master_array=${ARRAY}
i++
done
it gives me error at line 3: Variable syntax.
what is wrong here? any help is appreciated. (4 Replies)
Hi guys
could you please post links that explain how to use and manipulate arrays in c shell (.csh files) ? examples are useful too :rolleyes: (5 Replies)
Hello all...
I'd like to create a variable from an array element from two arrays. In my search for answers I found this code for bash that joins two arrays and then started to work with it. I had got to work once and then foolishly without saving the code, I started to edit it for ksh and... (4 Replies)
I need to create arrays like this:
cnt=0
{ while read myline; do
if ];then
firstpass="${myline##<meas>}"
meas="${firstpass%%</meas>}"
tempmeas="${meas%%;*}"
MEAS$cnt=$tempmeas
print $cnt
print ${MEAS'$cnt'}
... (2 Replies)
hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this:
_____________________________
func(){
#take in 1st arg as the arrayname
arrayName=$1
let i=0
while read line
do
arrayName=${line}
let i+=1... (5 Replies)