cpiety has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I have a file which looks like the sample data below

199901010000 0.316 6.1 263
199901010000 0.330 4.9 259


I have another file which looks like the sample data below

1999/01/01 00:00
1999/01/01 00:00

I would like to replace the first column (the bold section) of first data file with the contents of the second data file.

How would someone not well versed in programing do that with PERL?
thank you very much for any help.

Replies are listed 'Best First'.
Re: how to swap data from files
by ccn (Vicar) on Feb 02, 2005 at 20:17 UTC
    perl -pe 's{$(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)}{$1/$2/$3 $4:$5}' one. +txt > another.txt
      thanks, it seems to be working great. I guess I did not need to create another file with the date/time formatt that I was interested in.

      Charles
Re: how to swap data from files
by johnnywang (Priest) on Feb 02, 2005 at 20:35 UTC
    On the command line, type:
    perl -i.orig -pe 's|^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})|$1/$2/$3 $4:$ +5|' first_file
Re: how to swap data from files
by sh1tn (Priest) on Feb 02, 2005 at 20:38 UTC
    open RH, "2.txt" or die $!; /^(.+?)\s*$/ and push @new_content, $1 while <RH>; close RH; open RH, "1.txt" or die $!; /^\d+\s*(.+?)\s*$/ and push @old_content, $1 while <RH>; close RH; open WH, ">1.txt" or die $!; for(@new_content){ $count++; print WH "$_ $old_content[--$counter]\n" }
      Hi, the code you posted is nicely changing the date stamp to a format I can use but it is also rearranging the data in a way I can not understand. It seems like there are 3 repeating blocks of data with the same date time stamp that have all different data. thanks again