The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2007
jaganadh jaganadh is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 32
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
  #2 (permalink)  
Old 07-06-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
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);
Output

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?
  #3 (permalink)  
Old 07-06-2007
jaganadh jaganadh is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 32
excately .
Thanks a lot.
I am conducting some study on the Behavior of English language. I prepared this program to get some data.
I got excta solution
Thanks lot
Jaganadh.G
Linguist
  #4 (permalink)  
Old 07-06-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0