The UNIX and Linux Forums  


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
OpenMeetings 0.5 Final (Default branch) iBot Software Releases - RSS News 0 04-01-2008 12:10 AM
XLOGO 0.9.92 (final) (Default branch) iBot Software Releases - RSS News 0 03-30-2008 11:40 AM
Modifying the final output file charbel Shell Programming and Scripting 5 10-10-2006 02:36 PM
SOLARIS 10 final release pressy News, Links, Events and Announcements 0 02-01-2005 08:13 PM
Final Top mail servers cipango News, Links, Events and Announcements 0 08-13-2002 04:48 AM

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

Join Date: Feb 2006
Posts: 41
Final Output

Hi There,

I am having two output files having the following information:

Output1:
Name1 0
Name2 222
Name3 598
Name4 9800

Output2:
Name1 10
Name2 333
Name3 567
Name4 39003

as you can see the two output files have the same Name colom but different records for each name. Now, how can i generate a final output file having the same Name in it in one coloum and the two recrods of each name in 2 coloumns,i.e., the final output should be of the following format:

Name1 0 10
Name2 222 333
Name3 598 567
Name4 9800 39003

I am using bash shell. Any idea on that?
Thanks for your help.
  #2 (permalink)  
Old 06-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
The "join" command would work as long as the files are sorted.

See "man join".
  #3 (permalink)  
Old 06-29-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,798
look up the join command, it is meant to do just that.

Code:
join -j 1 file1 file2 > newfile

  #4 (permalink)  
Old 06-29-2006
Doc_RuNNeR Doc_RuNNeR is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 17
If you want a shell script you can use that

Code:
#! /bin/bash
espacios=IFS
IFS="
"
for i in `cat $1`
do
  name=`echo $i | cut -d" " -f1`
  echo $i > aux
  cat $2 | grep "^$name " | cut -d" " -f2 >> aux
  cat aux | tr -s "\n" " " >> aux2
  echo >> aux2
done
IFS=$espacios
unset espacios
rm aux

It generates a file whose name is aux2 that has the information that you want.

Bye
  #5 (permalink)  
Old 06-29-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
join command

This should work

join -i -1 1 -2 1 filename1 filename2 > joined_file

-i is for ignoring case

-1 and -2 specify the field numbers in file1 and file2 respectively( field 1 for both in this case).
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 02:10 PM.


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