Sponsored Content
Top Forums Shell Programming and Scripting Need help in creating arrays using shell Post 302533518 by jpkumar10 on Friday 24th of June 2011 02:11:50 AM
Old 06-24-2011
Need help in creating arrays using shell

Hi,

I need help in creating a array in shell scirpt.
I have a file which has following details.
Code:
hostname devices
device1
device 2
de
abcdmhs10 1234
2343
2353
3343
3435
2343
bcdfmhs11 2343
2443
3434
8874
0343
3434
efghnhy001 1234
4687
5673
5678
9857
3434

Above is my test file. I need to create a array in which should be following format.
Code:
array[abcdmhs10]=1234,2343,2353,3343,3435,2343
array [bcdfmhs11]=1234,4687,5673,5678,9857,3434

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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell: creating different arrays based on function argument

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)
Discussion started by: nix21
5 Replies

2. Shell Programming and Scripting

how to use arrays in c shell

hi :) i need help to explain arrays 2D in c shell like this in c++ int a (6 Replies)
Discussion started by: hgphsf
6 Replies

3. Shell Programming and Scripting

Creating an unknown number of arrays

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)
Discussion started by: ajgwin
2 Replies

4. Shell Programming and Scripting

Joining two arrays and then creating a variable

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)
Discussion started by: carlos25
4 Replies

5. Shell Programming and Scripting

C shell arrays

how do you declare an array in the C shell and loop through each element? (2 Replies)
Discussion started by: npatwardhan
2 Replies

6. Shell Programming and Scripting

I need help with arrays in C Shell

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)
Discussion started by: domain
5 Replies

7. Shell Programming and Scripting

arrays in C shell

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)
Discussion started by: npatwardhan
4 Replies

8. Shell Programming and Scripting

Using arrays in shell

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)
Discussion started by: anish
4 Replies

9. Shell Programming and Scripting

Shell arrays need help

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)
Discussion started by: stevenswj
3 Replies

10. Shell Programming and Scripting

Creating script with multiple job arrays

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)
Discussion started by: idbemad
3 Replies
WWW::Facebook::API::Users(3pm)				User Contributed Perl Documentation			    WWW::Facebook::API::Users(3pm)

NAME
WWW::Facebook::API::Users - Facebook Users SYNOPSIS
use WWW::Facebook::API; DESCRIPTION
Methods for accessing users with WWW::Facebook::API SUBROUTINES
/METHODS base Returns the WWW::Facebook::API base object. new Constructor. get_info( uids => $uids, fields => $fields ) The users.getInfo method of the Facebook API: $response = $client->users->get_info( uids => [ 2343, 3435 ], fields => 'about_me' ); $response = $client->users->get_info( uids => 2343, fields => [ qw/about_me quotes/ ] ); get_logged_in_user The users.getLoggedInUser method of the Facebook API: $uid = $client->users->get_logged_in_user; has_app_permission The users.hasAppPermission method of the Facebook API: $response = $client->users->has_app_permission( ext_perm => 'status_update|photo_upload' ); is_app_user The users.isAppUser method of the Facebook API: $app_added = $client->users->is_app_user; set_status The users.setStatus method of the Facebook API: $response = $client->users->set_status( status => 'status message', clear => 1|0, ); is_verified The users.isVerified method of the Facebook API: $verified = $client->users->is_verified; DIAGNOSTICS
None. CONFIGURATION AND ENVIRONMENT
WWW::Facebook::API::Users requires no configuration files or environment variables. DEPENDENCIES
See WWW::Facebook::API INCOMPATIBILITIES
None reported. BUGS AND LIMITATIONS
No bugs have been reported. Please report any bugs or feature requests to "bug-www-facebook-api@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. AUTHOR
David Romano "<unobe@cpan.org>" LICENSE AND COPYRIGHT
Copyright (c) 2007-2010, David Romano "<unobe@cpan.org>". All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. perl v5.10.1 2010-03-13 WWW::Facebook::API::Users(3pm)
All times are GMT -4. The time now is 03:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy