#! /usr/bin/perl

use strict;
use warnings;

my $str1 = "";
my $str2 = "";
my $res;

open(FILE, "numbers.txt") or die "Can't open the file 1 $!\n";
open(FILE1, ">test1.txt") or die "Can't open the file 2 $!\n";
open(FILE2, ">test2.txt") or die "Can't open the file 3 $!\n";
while (<FILE>)
{
  chomp;
  if($_ =~ /(\d+)\s+(\d+)/ ){
    printf FILE1 "$1 ";
    printf FILE2 "$2 ";
  }
}
printf FILE1 "\n";
printf FILE2 "\n";
close(FILE);
close(FILE1);
close(FILE2);

$res = `cat test1.txt test2.txt > sumfile.txt`;
$res = `rm -f test1.txt test2.txt`;

*Mukesh Kumar*

*Member of Technical Staff*
*Cadence Design Systems (I) Pvt. Ltd.*

*Mob:- +91-8527749333*


On 7 July 2014 13:48, Sunita Pradhan <sunita.pradhan.2...@hotmail.com>
wrote:

> I have a file of contents:
> -----------
> 1 6
> 2 7
> 3 8
> 4 9
> 5 10
> ----------
> I want a file with content:
>
> 1 2 3 4 5
> 6 7 8 9 10
>
> --------
> I have written a few lines of following code but it does not work as
> expected  :
>
> -------------------------------------------
> #!/usr/bin/perl
> use v5.10;
> use strict;
> use warnings;
>
> open(FILE, "numbers.txt") or die "can not open file . $!\n";
> open(FILE1, ">sumfile.txt") or die "can not open file . $!\n";
>
> my @lines = <FILE>;
> chomp @lines;
>
> my $c=0;
> while ($c <= $#lines){
>       if ($lines[$c] =~ /(\w+)\s+(\w+)/){
>            print FILE1 "$1\n";
>            print FILE1 "$2";
>
>       }
>
> $c++;
>        }
>
>        close FILE;
>        close FILE1;
> --------------------------
>
> Please guide me .
>

Reply via email to