Unix Shell for loop..... problems

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

bossman5000

Thread Starter
Joined
Nov 9, 2011
Messages
8
I need help please.write a shell script that will take the information from two files and combine into another file
I created both files in vi.



file1
David 734.854.5643
Roberto 313.432.4532
Sally 267.423.5412
Mary 435.432.7654
Ted 324.642.6743
Alice 234.576.3245
Frank 342.465.6754


second file

file2
Roberto Tuesday 2
Sally Monday 8
Ted Sunday 16
Alice Wednesday 23
David Thursday 10
Mary Saturday 14
Frank Friday 15




The output file should be like this:

Sally---------------- Monday ---------------267.423.5412-----------------8am
Roberto-------------Tuesday---------------313.432.4532-----------------2am
Alice---------------Wednesday-------------234.576.3245----------------11pm
David---------------Thursday---------------734.854.5643----------------10am
Frank----------------Friday------------------342.465.6754----------------3pm
Mary---------------Saturday-----------------435.432.7654----------------2pm
Ted-----------------Sunday------------------324.642.6743-----------------4pm

$file1 | sort > file1.sort
$file2 | sort > $file2.sort

echo -e "name\t days\t \phone numbers\t \Time\t"

for day in Monday Tuesday Wednesday Thursday Friday Saturday Sunday
name=`cat $file2.sort | grep $Oncall | cut -d, -f1`
if { $name }; then
phone = `cat file1.sort | grep $name | cut -d, -f2`
echo -e "$names\t \days\t \$phonenumbers \$Time
fi
done


Did I do the for loop right??
What else do i need to add to the loop.
how to loop around again??


Somebody help me Pleaseee



Thank You
 

bossman5000

Thread Starter
Joined
Nov 9, 2011
Messages
8
$file1 | sort > file1.sort
$file2 | sort > $file2.sort

echo -e "name\t days\t \phone numbers\t \Time\t"

for day in Monday Tuesday Wednesday Thursday Friday Saturday Sunday
name=`cat $file2.sort | grep $Oncall | cut -d, -f1`
if { $name }; then
phone = `cat file1.sort | grep $name | cut -d, -f2`
echo -e "$names\t \days\t \$phonenumbers \$Time
fi
done


Did I do the for loop right??
What else do i need to add to the loop.
how to loop around again??
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Been a while since I have done Bash Scripting but it seems like you could use the join command first and then manipulate that single merged file from the join cmd in a For loop.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top