in reply to Re^2: Splitting a Blocked file in Round Robin into smaller files
in thread Splitting a Blocked file in Round Robin into smaller files

Much better explanation, thank you. Try this:

#! perl -sw use strict; my $file = $ARGV[0]; open I, '<', $file or die $!; my @outs; open $outs[ $_ ], '>', "$file.$_" or die $! for 1 .. 4; my $out = 1; while( <I> ) { print { $outs[ $out ] } $_; if( /^5/ ) { ++$out; $out = 1 if $out > 4; } }

Call it as scriptname filename. The 4 output files will be named filename.1 filename.2 filename.3 filename.4


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Splitting a Blocked file in Round Robin into smaller files
by tradersjoe0 (Novice) on Dec 14, 2015 at 16:22 UTC

    Worked like a champ!!! Thank you so much for taking time...Really appreciate your help

Re^4: Splitting a Blocked file in Round Robin into smaller files
by tradersjoe0 (Novice) on Mar 09, 2016 at 14:27 UTC
    Hello BrowserUK,

    The above code works like a champ The 4 output files are named filename.1 filename.2 filename.3 filename.4

    Lets say filename= DummyFile.txt

    4 output files:DummyFile.txt.1,DummyFile.txt.2,DummyFile.txt.3,DummyFile.txt.4

    I am trying to get the file names as below

    4 output files:DummyFile1.txt,DummyFile2.txt,DummyFile3.txt,DummyFile4.txt

    The number comes before the delimiter "."

    Any help will be much appreciated

      This assumes that the input filename contains at least one dot. The number will precede the last dot in the input:

      #! perl -sw use strict; my $file = $ARGV[0]; my( $prefix, $suffix ) = ( $file =~ m[^(.+)\.([^.]+)] ); open I, '<', $file or die $!; my @outs; open $outs[ $_ ], '>', "$prefix.${_}.$suffix" or die $! for 1 .. 4; my $out = 0; while( <I> ) { print { $outs[ $out+1 ] } $_; if( /^5/ ) { ++$out; $out %= 4; } }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Thank you so much BrowserUk, It worked perfect.