Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2004
    Posts
    52

    Arrow Unanswered: copy/paste columns

    Hi.

    I have two files with hundreds of columns on each of them.
    Let's say :

    <file 1> <file 2>

    1 a q1 ... 12 4 65 ... e
    2 b e2 ... a 0 ty ... 33
    3 c s ... 3d 7 5t ... 21q
    ... .. .. ... zz ... .. .. d4
    N B 43 ... d4 t5 44 .. b3

    How can I build a third file with these columns intercalated ?

    <file 3>

    1 4 a 65 q1 ...e 12
    2 0 b ty e2 ...33 a
    3 7 c 5t s ...21q 3d
    .. .. .. .. . .. ...d4 zz
    N t5 B 44 43 ... b3 d4

    Thanks,

    Serg

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    man paste

    vlad

  3. #3
    Join Date
    Feb 2004
    Posts
    52
    Vlad,

    Thanks for the suggestion but "paste" does not work in this problem.
    I need to intercalate column by column from both files.
    I can not simply attach the two files.

    Thanks,

    Serg

  4. #4
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Thanks for the suggestion but "paste" does not work in this problem.
    Sure it does...

    Paste the file together, then order the fields.
    Code:
    paste file1 file2 | awk '{print $1,$3,$2,$4}'
    Damian

  5. #5
    Join Date
    Feb 2004
    Posts
    52
    Thanks, Damian.

    It worked fine !!!

  6. #6
    Join Date
    Feb 2004
    Posts
    52
    Damian,

    I forgot to mention...the real problem
    deals with 400 columns on each file (therefore
    the output will have 800 columns).

    Serg

  7. #7
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Code:
    paste f1 f2 | awk '{for (i=1; i<=NF/2; i++){printf "%s %s ",$i,$NF/2+1};printf "\n"}'

  8. #8
    Join Date
    Feb 2004
    Posts
    52
    Thanks a lot, Damian !!!!!!!!!!!!!!!!!!

  9. #9
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Oops! Looking at that again, I think I made a mistake with the printf output...

    Code:
    awk '{for (i=1; i<=NF/2; i++){printf "%s %s ",$i,$NF/2+i};printf "\n"}'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •