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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combining files horizontally anshuljain HP-UX 3 03-14-2008 05:51 AM
Combining Two Files stevefox Shell Programming and Scripting 4 02-20-2006 05:09 AM
Combining Two Files bat711 Shell Programming and Scripting 3 10-05-2005 01:26 PM
Combining files Enda Martin UNIX for Dummies Questions & Answers 2 07-20-2001 10:31 AM
combining files apalex UNIX for Dummies Questions & Answers 3 06-19-2001 09:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2007
hemangjani hemangjani is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 73
Exclamation Combining two files

I have two files and I need to combine (not append - but combine a row to a row)

eg:
File1:
apples
grapes
oranges
lemons

File2:
red
green
orange
yellow

After combining, the file should look like: (the second column should start at a specific byte)
apples red
grapes green
oranges orange
lemons yellow

Thanks
  #2 (permalink)  
Old 06-12-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
'man paste'
  #3 (permalink)  
Old 06-12-2007
hemangjani hemangjani is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 73
Red face

Thanks for the reply.

I tried the paste and it worked but the tab is not adjusted and this was my fear.

eg: after paste

apples red
grapes green
oranges orange
lemon yellow

I was wondering something like the first line of file 1 stars at the 1 postion of the line and the first line of file 2 starts at the 60th position of the line.

Thanks again.
  #4 (permalink)  
Old 06-12-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
you can specify delimiters (TAB by default) with the '-d' switch.
  #5 (permalink)  
Old 06-13-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Try this awk program:
Code:
#!/usr/bin/awk -f
#Awk program : paste.awk

function readFile(i,    rec) {
   if (getline rec < ARGV[i])
      return rec;
   else {
      ++eof[i];
      return "";
   }
}

BEGIN {
   while (1) {
      rec1 = readFile(1);
      rec2 = readFile(2);
      if (eof[1] && eof[2]) break;
      printf("%-60s%s\n", rec1, rec2);
   }
   exit;
}
Output:
Code:
$ awk -f paste.awk file1.txt file2.txt
apples                                                      red
grapes                                                      green
oranges                                                     orange
lemons                                                      yellow
$
Jean-Pierre.
  #6 (permalink)  
Old 06-13-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Or...
Code:
paste file1 file2 | awk -F '\t' '{printf "%-60s%s\n", $1, $2}'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0