Thanx Craig. That worked. I have another question.
I would like to create an array in the folowing format: 123 abc,xyz,pqr 234 xyz 456 wer,tre --- --- I want to use a command like the following push @first_array, <the_number> <tab> <group of words separated by commas from second_array>; where the_number = values in 1st column coming from a variable in a loop. The values in second column are from second_array. abc, xyz, pqr etc.. are individual elements in second_array. I also don't know how to insert commas in between the individual elements ( i.e. a comma between abc and xyz and so on while creating the array) Thanx.. -Bheem -----Original Message----- From: Arnold, Craig [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 1:07 PM To: AITHA, BHEEMSEN (SBCSI); '[EMAIL PROTECTED]' Subject: RE: [Perl-unix-users] Please help on GREP command You appear to be trying to use the command-line version of grep, rather than a Perl grep. To get what you appear to be looking for in Perl would require opening the file: Script: grep.pl #!perl -w use strict ; my $fn = "test.txt" ; open(INFILE, $fn) or die "Can't open input file: $fn ($!)" ; my @match_lines = grep /abc|xyz|pqr/i, <INFILE> ; print @match_lines ; print scalar(@match_lines) ; print "Found it!\n" if @match_lines ; close INFILE ; File: test.txt ABC 1121 xyz 2234 pqr this is a test Output: ABC xyz pqr 3 Found it! You should avoid using the backtick operator because it is far slower than the equivalent Perl code. Also, the shell command (in this case grep) might not be implemented the same on all platforms - the command you have listed works on my HP-UX system, but doesn't work on my Win2k or Sun computers. One last thing - you can do far more with Perl's grep than you can with the shell grep. See perldoc -f grep (and map) for more info. Craig Arnold Boeing Space & Comm International Space Station Guidance, Navigation & Control Huntington Beach, CA -----Original Message----- From: AITHA, BHEEMSEN (SBCSI) [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 11:23 AM To: '[EMAIL PROTECTED]' Subject: [Perl-unix-users] Please help on GREP command Hi listers, I am using the following command in my perl script. But when I execute the script I am getting the error "Unrecognized file test: -E at test.pl line 9." grep -E -i -c "abc|xyz|pqr" test.txt ; Can someone please tell me what I am doing wrong here ? All I wanted to do is to search for any of the stings abc, xyz or pqr in the file test.txt. Thanx.. -Bheem _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs