I'm currently working on trying to merge two files together on unix
first file:
Tom 313.455.6786
Deena 313.899.7400
Will 313.845.5633
Nancy 313.676.9445
Kelly 313.611.4242
John 313.908.3858
second file:
Deena Tuesday
Will Monday
Kelly Sunday
John Wednesday
Tom Thursday
Nancy Saturday
I'm writing the script in the korn shell and I need to include for loops and arrays and all that jazz.
This is what I have so far:
#!/bin/ksh
file1=/home/file1
file2=/home/file2
set -A name
set -A phone
set -A day
for input in `cat file1| cut -d " " -f1`
do
name=$input
done
for input2 in `cat file1|cut -d " " -f2`
do
phone=$input2
done
for input3 in `cat file2|cut -d " " -f2`
do day=$input3
week= "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
for day in $week
do
echo $day\n
day=$i
done
done
printf "%s\t%-12s\t%s\n" "Name" "On-Call" "Phone"; join < (sort file1) <
(sort file2) | tr ' ' '\t'
This scipt is giving me the following output:
Name On-Call Phone
Deena 313.899.7400 Tuesday
John 313.908.3858 Wednesday
Kelly 313.611.4242 Sunday
Nancy 313.676.9445 Saturday
Tom 313.455.6786 Thursday
Will 313.845.56334 Monday
That code sorted the files by alphabetizing the names, rather than by the weekdays, which is what I need. Also it's reversing the On-call output with the Phone output.
I need the final file to look exactly like this
Name On-Call Phone
Will Monday 313.845.5633
Deena Tuesday 313.899.7400
John Wednesday 313.908.3858
Tom Thursday 313.455.6786
Nobody Friday 313.555.3454
Nancy Saturday 313.676.9445
Kelly Sunday 313.611.4242
printf "%s\t%-12s\t%s\n" "Name" "On-Call" "Phone"; join <(sort file1) <(sort file2) | tr ' ' '\t'