Final Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Final Output
# 1  
Old 06-29-2006
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  
Old 06-29-2006
The "join" command would work as long as the files are sorted.

See "man join".
# 3  
Old 06-29-2006
look up the join command, it is meant to do just that.
Code:
join -j 1 file1 file2 > newfile

# 4  
Old 06-29-2006
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  
Old 06-29-2006
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Separating output after final character

I'm trying to write a script that will email the contents of my Application folder to me. cd /Applications ListApps=$(ls) echo $ListApps | mail -s "Application Check" myself@myemail.com This sends it in a paragraphed block i.e: Adobe Acrobat Reader.app App Store.app Atom.app... (4 Replies)
Discussion started by: $shell_Learner
4 Replies

2. Shell Programming and Scripting

Addition to Bash shell script that emails final output as attachement?

Greetings. I have a nice bash shell script that runs a multi-step analysis well. I already have the SGE options set up to email me the progress of the run (started, completed, aborted), but a final step would be to code the shell script to email the final output (a .txt file) to the same email... (6 Replies)
Discussion started by: Twinklefingers
6 Replies

3. UNIX for Dummies Questions & Answers

LINUX - How to remove the final delimiter from a command output

Hi All, I am trying to list the various dates for which the file is available in a directory using the command below, (& subsequently pass the command output to a loop) Command : ls dir|grep 'filename'|cut -d '_' -f1|cut -c1-8|tr '\n' ',' However, it is giving me an extra comma... (6 Replies)
Discussion started by: dsfreddie
6 Replies

4. Shell Programming and Scripting

Modifying the final output file

Hey all, I am haivng n number of files all of them are of the same format but different details. i.e File1 is having the folloeing details: "Account1",123 "Account2",10 "Account3",12355 "Accountn",555 File2 is having the folloeing details: "Account1",1234 "Account2",100... (5 Replies)
Discussion started by: charbel
5 Replies
Login or Register to Ask a Question