Find the answer to your Linux question:
Results 1 to 3 of 3
hello every one I have a problem that drove me crazy last couple days I know I have to use loop structures but I can't figure out how to put ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    4

    looping problem in UNIX script please help


    hello every one
    I have a problem that drove me crazy last couple days I know I have to use loop structures but I can't figure out how to put the right pieces together. I'm not asking for a complete answer because I want to learn so please help me out
    The problem says
    write a shell script that will take the information from two files and combine into another file
    I created both files in vi and they are




    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





    and the second file is


    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:
    Name----------------On-Call--------------------Phone------------------Start Time
    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





    I noticed right away that there is a common thing between the two files (the name), and I thought i could use for loop to cut pieces using the day of the week because I have to sorted in a specific order starting from Monday so I thought this loop might work:



    for day in Monday Tuesday Wednesday Thursday Friday Saturday Sunday
    do
    grep $day file2
    Done



    I know it is not complete but I just wanted you to know how I should do the sort. And there is another problem which is the time. in the file is in 24 hours format i have to convert it to 12 hours format.
    And that is it for now I want you guys just to tell me how to start and how to put the pieces together.
    your help us appreciated
    Thank you very much

  2. #2
    Just Joined!
    Join Date
    Oct 2011
    Posts
    4
    64 views and no help


    help me out here guys please.

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    This sounds a lot like a homework question, which are not allowed on this forum. Therefore, I will be closing this thread.

    You are correct that you can use grep to find which lines contain a given word. Have you considered using cut or awk in order to get the rest of the information on that line?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •