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

Dear Monks, I was trying to add a row of my data to another file but alas !! couldn't do it. I have 2 files and I need to copy one row of a file to make it the first row of the other file :-
File 1:- New_York South_Street 334473 Los_Ange West_Street 829839 Californ North_Street 748723 File 2:- David John Mathew
I want the result like this
RESULT file:- David New_York South_Street 334473 John Los_Ange West_Street 829839 Mathew Californ North_Street 748723
I tried but not able to do :(. Is there any PERL One liner for this ??
Thanks

Replies are listed 'Best First'.
Re: Adding row from other file
by dHarry (Abbot) on Nov 06, 2008 at 11:24 UTC

    Why don't you show some code/effort? Also you mix row and column. It appears you want to insert the column of file 2 before the columns of file 1. If you first write down the steps to take you're almost there. Like for example:

    1. open the two files for reading, open a new file for writing
      1. In a loop:
      2. read line from file 1
      3. read line from file 2
      4. combine lines
      5. write combined line to file 3
    2. close the files

    And why do you want a one-liner for this? And it's Perl and not PERL (yes I am grumpy today)

      Dear Harry I am sorry I made u angry. I am still learning and will be better next time.

        Learning is good. Everyone was a learner once and hopefully can remember what it was like. The way the question was posed, however, appeared to be asking for the code to be written for you.

Re: Adding row from other file
by gone2015 (Deacon) on Nov 06, 2008 at 11:20 UTC

    The required result appears to be a new column rather than a new row. So that's a worry.

    What have you tried that doesn't quite work for you ? Reading two files, line by line, and concatenating each line seems to be roughly what you want ?

Re: Adding row from other file
by repellent (Priest) on Nov 07, 2008 at 01:38 UTC
    If in Unix, no need for Perl:
    $ cat file1.txt New_York South_Street 334473 Los_Ange West_Street 829839 Californ North_Street 748723 $ $ cat file2.txt David John Mathew $ $ paste file2.txt file1.txt # separate with "\t" David New_York South_Street 334473 John Los_Ange West_Street 829839 Mathew Californ North_Street 748723 $ $ man paste # please read
A reply falls below the community's threshold of quality. You may see it by logging in.