The UNIX and Linux Forums  


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
Help fix my garbage - File Split Program in Perl mkastin Shell Programming and Scripting 4 06-27-2009 12:44 AM
perl help to split big verilog file into smaller ones for each module return_user Shell Programming and Scripting 7 05-12-2009 10:44 PM
split a file but output file is fixed RahulJoshi Shell Programming and Scripting 3 01-07-2009 11:05 PM
Split a file based on pattern in awk, grep, sed or perl kumarn Shell Programming and Scripting 5 06-20-2008 11:51 AM
Perl Script : Split given month into weeks khushbu_roy Shell Programming and Scripting 5 02-22-2008 11:40 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-25-2009
ashvini ashvini is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 1
how to get split output of a file, using perl script

Hi,
I have file: data.log.1
### s1
main.build.3495
main.build.199
main.build.3408

###s2
main.build.3495
main.build.3408
main.build.199

I want to read this file and store in two arrays in Perl.
I have following command, which is working fine on command prompt.

perl -n -e '/^###/ and open FH, ">output_".$n++; print FH;' data.log.1

But I want to use this command in Perl file, so that I can store output ###s1 (part) and ###s2 (part) in two different arrays.

Any help will be appreciated.

Thanks
  #2 (permalink)  
Old 08-25-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 547
Here's one way to do it in Perl:


Code:
$ 
$ cat data.log.1
###s1
main.build.3495
main.build.199
main.build.3408

###s2
main.build.3495
main.build.3408
main.build.199
$ 
$ ##
$ perl -ne 'chomp;
>           if (/^###s1/) {$s1=true} elsif(/^###s2/) {$s2=true}
>           if ($s2) {push @s2,$_} elsif($_ ne "" && $s1) {push @s1,$_}
>           END {print "Array \@s1:\n";foreach $i (@s1) {print $i,"\n"}
>                print "Array \@s2:\n";foreach $i (@s2) {print $i,"\n"}}' data.log.1
Array @s1:
###s1
main.build.3495
main.build.199
main.build.3408
Array @s2:
###s2
main.build.3495
main.build.3408
main.build.199
$

tyler_durden
Reply

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 05:32 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