perl, put one array into many array when field is equal to sth


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl, put one array into many array when field is equal to sth
# 1  
Old 06-06-2010
perl, put one array into many array when field is equal to sth

Hi Everyone,

Code:
#!/usr/bin/perl
use strict;
use warnings;

my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d");

would like to split the @test array into two array:
@test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d");

means search for 3rd filed.

Thanks

find the answer,
my @match = grep (/qqq/i, @test);

Last edited by jimmy_y; 06-06-2010 at 07:04 AM.. Reason: found the solution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : Large amount of data put into an array

This basic code works. I have a very long list, almost 10000 lines that I am building into the array. Each line has either 2 or 3 fields as shown in the code snippit. The array elements are static (for a few reasons that out of scope of this question) the list has to be "built in". It... (5 Replies)
Discussion started by: sumguy
5 Replies

2. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

3. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

4. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

5. Shell Programming and Scripting

perl sum 2nd field in an array

Hi Everyone, ($total+=$_) for @record; assume @record=(1,2,3), so the result is 6. if @record=("1 3","2 3","3 3"), would like to sum up the 2nd field of this array, the result is 9. i tried " ($total+=$) for @record ", cannot, please advice. Thanks ---------- Post updated at 03:45... (1 Reply)
Discussion started by: jimmy_y
1 Replies

6. Shell Programming and Scripting

perl sort array by field

Hi Everyone, Any simple code can simplify the code below, please advice. Thanks # cat 2.pl #!/usr/bin/perl use warnings; use strict; my @aaaaa = <DATA>; my @uids; foreach (@aaaaa) { my @ccccc = split (",", $_); push @uids, $ccccc;... (3 Replies)
Discussion started by: jimmy_y
3 Replies

7. Shell Programming and Scripting

Put output into an array

I'm trying to take the output of an environment that has multiple strings ex. # echo $SSH_CLIENT 192.168.1.1 57039 22 I need that IP... so I can set it to another environment. Thank you (3 Replies)
Discussion started by: adelsin
3 Replies

8. Shell Programming and Scripting

Perl grep array against array

Hi, Is there any way I can grep an array against another array? Basically here's what I need to do. There will be an array containing some fixed texts and I have to check whether some files contain these lines. Reading the same files over and over again for each different pattern doesnt seem... (1 Reply)
Discussion started by: King Nothing
1 Replies

9. Shell Programming and Scripting

Perl - if conditions is meet, push the last field of $_ into an array

I am using a seed file shown below to separate cisco devices by ios/os type. I want to bunch all the devices based on ios/os version. Once I find a match, I only want to push the ip address into the appropriate array. Example of seedfile 8 host1 (C3500XL-C3H2S-M) 11.0(5)WC17 10.1.44.21 9... (1 Reply)
Discussion started by: popeye
1 Replies

10. Shell Programming and Scripting

Setting array equal to command response

normally when i type: condor_q | tail -1 command line returns: 0 jobs; 0 idle, 0 running, 0 held I want use the number in front of 'running' in a series of equality tests to submit more jobs when my queue gets low. Someone showed me how to do it a few days ago by setting an array equal to... (4 Replies)
Discussion started by: pattywac
4 Replies
Login or Register to Ask a Question
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh. Note that /etc/shells overrides the default list. Invalid shells in /etc/shells may cause unexpected behavior (such as being unable to log in by way of ftp(1)). FILES
/etc/shells lists shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.10 4 Jun 2001 shells(4)