Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-09-2010
Registered User
 

Join Date: Sep 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
How to get list of user into an array..

Hi,

cut -d: -f1,3 /etc/group >rpt.out

I have a doubt in above unix commands. right i am getting list of group user id into rpt.out file. instead i need to store it as an array. could you please tell me how can i get list of user into an array..

If u could tell me give me in perl script code in unix

thanks in advance.
Sponsored Links
    #2  
Old 09-09-2010
frans's Avatar
frans frans is offline Forum Advisor  
Registered User
 

Join Date: Oct 2009
Location: France
Posts: 837
Thanks: 4
Thanked 52 Times in 51 Posts
bash
Code:
A=( $(cut -d: -f1,3 /etc/group | tr '\n' ' ') )
echo "Number of elements in array: ${#A[@]}"
echo "Elements of array: ${A[@]}"

Sponsored Links
    #3  
Old 09-09-2010
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
To emulate cut:

Code:
open my $group, '<', '/etc/group';
my @groups = map { my @a = split /:/; $a[0] . ':' . $a[2] } <$group>;
close $group;

To create a hash mapped on the group name:
Code:
open my $group, '<', '/etc/group';
my %groups = map { my @a = split /:/; $a[0], $a[2] } <$group>;
close $group;

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple list file ls to an array cyberfrog Shell Programming and Scripting 6 07-13-2010 01:50 PM
How to process list of files as array in the script IND123 Shell Programming and Scripting 1 06-07-2010 06:37 AM
storing values in a list or array KiranKumarKarre Shell Programming and Scripting 1 05-08-2009 12:50 AM
Searching for array in large list of files Rhije Shell Programming and Scripting 2 01-21-2009 11:11 PM
getting data list into a hash array topcat8 Shell Programming and Scripting 5 03-09-2004 11:02 AM



All times are GMT -4. The time now is 04:13 AM.