The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 10-10-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,875
I would use Perl directly:

Code:
$ head file*
==> file1 <==
1
2
3
4
5
6

==> file2 <==
 9    66 8  a
 8    3  9  b
 66   4  25 c
 66   2  6  d 
 4    3  3  e
 4    5  45 f
$ perl -e'
  open F1,"<file1"or die$!;open F2,"<file2"or die$!;
  s/([^\s]+)\s*/<F1>/eand s/\n/\t/and print while<F2>;
  close F1;close F2'         
 1      66 8  a
 2      3  9  b
 3      4  25 c
 4      2  6  d 
 5      3  3  e
 6      5  45 f

Last edited by radoulov; 10-10-2008 at 09:43 AM.. Reason: refactored (still quite new to Perl ...)