LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-12-2018, 04:42 PM   #16
Pothole1127
LQ Newbie
 
Registered: Apr 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Code need help with


Code:
1 #! /bin/bash
  2 echo "**************************************************************"
  3 echo
  4 echo "Katie Carter"
  5 echo "Project 2  CIS 129 Section #01"
  6 date
  7 echo "**************************************************************"
  8 echo
  9 echo "NAME              ON-CALL       PHONE     START TIME"
 10 echo "****              *******       *****     **********"
 11 for day in Monday Tuesday Wednesday Thursday Friday Saturday Sunday
 12 do
 13         name=`grep $day project2.2.input | cut -d " " -f1`
 14                 if [ ! $name ] ; then
 15                      printf Nobody
 16                 fi
 17         time=`grep $day project2.2.input | cut -d " " -f3`
 18                 if [ $time -gt 12 ] ; then
 19                        calctime=`expr $time - 12`
 20                        AMPM=PM
 21                else
 22                        calctime=$time
 23                        AMPM=AM
 24                 fi
 25         phone=`grep $name project2.1.input | cut -d " " -f2`
 26         printf "%-15s %-15s %-15s %-15s\n" $name $day $phone $time
 27 done < project2.1.input < project2.2.input
 
Old 04-12-2018, 05:30 PM   #17
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You don't need the stdin redirection " < project2.1.input < project2.2.input " after done in end of loop because data file is read passing filename as grep argument...

Another way to get time in 12h format if using GNU date
Code:
time=$(grep $day project2.2.input | cut -d " " -f3)
time=$(LC_TIME=C date -d $time +"%I:%M %p")
 
Old 04-12-2018, 05:32 PM   #18
Pothole1127
LQ Newbie
 
Registered: Apr 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
how would you do the 24 hour format though?
 
Old 04-12-2018, 05:34 PM   #19
Pothole1127
LQ Newbie
 
Registered: Apr 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
You don't need the stdin redirection " < project2.1.input < project2.2.input " after done in end of loop because data file is read passing filename as grep argument...

Another way to get time in 12h format if using GNU date
Code:
time=$(grep $day project2.2.input | cut -d " " -f3)
time=$(LC_TIME=C date -d $time +"%I:%M %p")
How do you do the 24 hour format?
 
Old 04-12-2018, 05:37 PM   #20
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
For 24h format
Code:
time=$(grep $day project2.2.input | cut -d " " -f3)
time=$(date -d $time +"%H:%M")
Have a look at date manual (man date)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Including basic linux OS code as a library package into a CCSv5 project for TCI6636 ? cmtht Linux - Embedded & Single-board computer 2 06-06-2013 12:27 AM
configuring laptop C drive into half windows 7 and half linux muddyholiday Linux - Newbie 6 03-16-2012 04:30 AM
(Ubuntu) Ethernet connection duplex stuck on half, cannot change to ful skyhopper88 Linux - Wireless Networking 2 02-14-2007 03:32 PM
Debian - Stuck in Half Duplex mode coldfusioner Linux - Networking 1 11-06-2006 03:17 PM
how do I install half windows98 half linux? xandar Linux - General 3 09-07-2005 03:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration