If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > copy/paste columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 10:36
Serg Serg is offline
Registered User
 
Join Date: Feb 2004
Posts: 52
Arrow 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
Reply With Quote
  #2 (permalink)  
Old 06-09-04, 10:49
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
man paste

vlad
Reply With Quote
  #3 (permalink)  
Old 06-10-04, 11:08
Serg Serg is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 06-10-04, 12:45
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Quote:
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
Reply With Quote
  #5 (permalink)  
Old 06-10-04, 15:24
Serg Serg is offline
Registered User
 
Join Date: Feb 2004
Posts: 52
Thanks, Damian.

It worked fine !!!
Reply With Quote
  #6 (permalink)  
Old 06-10-04, 15:25
Serg Serg is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 06-11-04, 06:55
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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"}'
Reply With Quote
  #8 (permalink)  
Old 06-14-04, 08:26
Serg Serg is offline
Registered User
 
Join Date: Feb 2004
Posts: 52
Thanks a lot, Damian !!!!!!!!!!!!!!!!!!
Reply With Quote
  #9 (permalink)  
Old 06-14-04, 08:29
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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"}'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On