Joining the content of two files from one-liner (still too long):
perl -ne 'chomp;push@{($|?"_0":"_1")},$_;eof&&$|++;END{$,=$?||map{print$_1[$-+ ++],$_,$/}@_0}' file1 file2


Replies are listed 'Best First'.
Re: join program in one-liner
by eric256 (Parson) on Aug 19, 2005 at 18:28 UTC

    How about: perl -lne"@a[$i++].=$_;$i=0 if eof;END{print for @a}"

    Update: fixed little cut and paste error


    ___________
    Eric Hodges
Re: join program in one-liner
by Joost (Canon) on Aug 19, 2005 at 19:08 UTC

      Yea i was going to do that but had to contort it a bit for my one above.


      ___________
      Eric Hodges
Re: join program in one-liner
by Anonymous Monk on Aug 19, 2005 at 17:11 UTC

    In a one-liner, you can auto-chomp and auto-newline with "-l". You'll save 9 characters.

    perl -ne 'push@{($|?"_0":"_1")},$_;eof&&$|++;END{$,=$?||map{print$_1[$-++],$_} +@_0}' file1 file2

      I forgot the -l ...

      perl -lne 'push@{($|?"_0":"_1")},$_;eof&&$|++;END{$,=$?||map{print$_1[$-++],$_} + @_0}' file1 file2
Re: join program in one-liner
by themage (Friar) on Aug 19, 2005 at 20:21 UTC
    Hi ppl,

    A little better than [id://eric256], based in the [id://Joost]'s idea:

    perl -lne '$a[$.].=$_;$.=0 if eof;END{print for@a}'

    I don't know also why $. don't reset, but we can always help it.

      Same as yours, but cut out unnecessary space and get rid of the END block:

      # 1 2 3 4 #23456789012345678901234567890123456789012345 perl -lne'$a[$.].=$_;$.=0if eof}{print for@a'

      BTW, perldoc perlvar says:

      $. is reset when the filehandle is closed, but not when an open filehandle is reopened without an intervening close(). For more details, see "I/O Operators" in perlop. Because "<>" never does an explicit close, line numbers increase across ARGV
        And $.=0if eof can be changed:
        # 1 2 3 4 #234567890123456789012345678901234567890123 perl -lne'$a[$.].=$_;$.*=!eof}{print for@a'