![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| split variable values into array | finalight | Shell Programming and Scripting | 4 | 05-21-2008 03:21 AM |
| Access value outside awk or split value of array | jason.bean | UNIX for Dummies Questions & Answers | 1 | 11-26-2007 04:33 PM |
| split varibles and store fields into shell varible array | gratus | Shell Programming and Scripting | 3 | 10-11-2007 02:50 PM |
| [KSH] Split string into array | piooooter | Shell Programming and Scripting | 3 | 09-01-2007 12:22 PM |
| How to get array to not split at spaces? | jjinno | Shell Programming and Scripting | 1 | 07-20-2007 12:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
split to array in perl
Collegues
I have flat file in the following format. 137 (NNP Kerala) (NNP India) 92 (NN Rent) (NN Range) 70 (NNP Thiruvananthapuram) (NNP Kerala) 43 (NNP Tourist) (NNP Home) 40 (NNP Reserve) (NNP Now) 25 (SYM @) (NN hotelskerala) 25 (NNP Thiruvananthapuram-695001) (NNP Kerala) 23 (NN Reservation) (IN For) 23 (NNP Now) (NNP mailto) 21 (NNP com) (NN <s/s>) 21 (VBZ subject=) (NN Reservation) 21 (NN <s/s>) (NN <s>) 21 (NN <s>) (VBZ subject=) 18 (NNP Aristo) (NN Junction) 16 (NNP Medical) (NNP College) 16 (NNP Road) (NNP Thiruvananthapuram) 14 (IN For) (NNP Hotel) 14 (NNP Thiruvananthapuram-695011) (NNP Kerala) 13 (NNP com) (NNP Reserve) 11 (NNP Thampanoor) (NNP Thiruvananthapuram) I tried to split and store it in to an rray using the code Code ________________________________________ open (PARSE,file2); @mwe = split(/\n/,<PARSE>); print "@mwe\n"; foreach $mwe(@mwe) { if ($mwe =~ m/[0-9]+ (NNP [A-z]+) (NNP [A-z]+)/) { print "$mwe\n"; } else { print " hi hi..... \n"; } } close (PARSE); -------------------------------------------------------------------- But it is not working. Any solution With thanks and regards Jaganadh.G Linguist |
|
||||
|
Code
Code:
#!/bin/perl
open (PARSE,file2);
@mwe = <PARSE>;
foreach $mwe (@mwe) {
if ($mwe =~ /[\d]+\s+\(NNP [\w\s]+\) \(NNP [\w\s]+\)/) {
print "$mwe\n";
}
else{
print " hi hi..... \n";
}
}
close (PARSE);
Code:
137 (NNP Kerala) (NNP India) hi hi..... 70 (NNP Thiruvananthapuram) (NNP Kerala) 43 (NNP Tourist) (NNP Home) 40 (NNP Reserve) (NNP Now) hi hi..... hi hi..... hi hi..... 23 (NNP Now) (NNP mailto) hi hi..... hi hi..... hi hi..... hi hi..... hi hi..... 16 (NNP Medical) (NNP College) 16 (NNP Road) (NNP Thiruvananthapuram) hi hi..... hi hi..... 13 (NNP com) (NNP Reserve) 11 (NNP Thampanoor) (NNP Thiruvananthapuram) Is this the one that you were looking for? |
|
||||
|
FYI
this is a cheating way to accept files on command line or a named one if none Code:
@ARGV = ("filename") unless @ARGV;
# then
@A = <>; # slurp the file(s)
or
while (<>) # read line by line for all files
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|