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.
The "join" command would work as long as the files are sorted.
See "man join".
look up the join command, it is meant to do just that.
join -j 1 file1 file2 > newfile
If you want a shell script you can use that
#! /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
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).