Reading in MM/DD/YY, find Day of Week


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading in MM/DD/YY, find Day of Week
# 8  
Old 07-22-2014
Quote:
Originally Posted by gjws
Thanks, but I think you missed the point of my post. I need to convert the date that is contained in the file, in to a day of the week. I do not need to know the current day of the week according to the system.
Did you try running the suggestion Chubler_XL suggested before saying it won't work? His code won't print the current day's day of week, it will either give you a diagnostic saying that the date utility doesn't recognize a --date option, or it will do what you requested.

What OS are you using?

Maybe I don't understand what you're trying to do. You said you want the output:
Code:
07/01/14 15:47:22               179.9500      MONDAY
07/01/14 16:03:29               3.9500        MONDAY
06/26/14 11:59:43               19.8000	      WEDNESDAY
06/27/14 12:02:43               160.0000      TUESDAY
07/02/14 13:12:35               5.9500        FRIDAY
07/02/14 13:34:17               5.9500        SATURDAY

July 1, 2014 was a Tuesday; not a Monday.
June 26, 2014 was a Thursday; not a Wednesday.
June 27, 2014 was a Friday; not a Tuesday.
And, July 2, 2014 was a Wednesday; not a Friday and a Saturday???
# 9  
Old 07-22-2014
Quote:
Originally Posted by Don Cragun
Did you try running the suggestion Chubler_XL suggested before saying it won't work? His code won't print the current day's day of week, it will either give you a diagnostic saying that the date utility doesn't recognize a --date option, or it will do what you requested.

What OS are you using?

Maybe I don't understand what you're trying to do. You said you want the output:
Code:
07/01/14 15:47:22               179.9500      MONDAY
07/01/14 16:03:29               3.9500        MONDAY
06/26/14 11:59:43               19.8000	      WEDNESDAY
06/27/14 12:02:43               160.0000      TUESDAY
07/02/14 13:12:35               5.9500        FRIDAY
07/02/14 13:34:17               5.9500        SATURDAY

July 1, 2014 was a Tuesday; not a Monday.
June 26, 2014 was a Thursday; not a Wednesday.
June 27, 2014 was a Friday; not a Tuesday.
And, July 2, 2014 was a Wednesday; not a Friday and a Saturday???
Firstly, if I sounded dismissive I certainly did not intend my post to appear so, I genuinely appreciate people sharing their experience freely with novices like myself. So Chubler_XL if my post came across as offensive then I sincerely apologise.

No, I did not try the example, I read it with my unqualified skill level and assumed it would simply return todays date. I should have actually taken the time to type this in to the terminal, when I did, it indeed returned what I needed.

As for the erroneous data in my post, I simply hand typed some days against the original data, that is the reason the days chosen do not match the actual dates, it was purely for illustration purposes.

Again thank you to everyone for you assistance, and apologies for my incorrect assumptions. Lesson learned, when you don't know what you are talking about (that's me!), it's best to shut up Smilie
# 10  
Old 07-22-2014
Quote:
Originally Posted by gjws
... ... ...

No, I did not try the example, I read it with my unqualified skill level and assumed it would simply return todays date. I should have actually taken the time to type this in to the terminal, when I did, it indeed returned what I needed.

... ... ...

Again thank you to everyone for you assistance, and apologies for my incorrect assumptions. Lesson learned, when you don't know what you are talking about (that's me!), it's best to shut up Smilie
We don't want you to shut up. We want you to learn. When you ask a question, and you get one or more suggestions; if you don't understand what it does:
  1. try it, or
  2. look at the man page for the suggested utility to see what it should do, or
  3. both.
And then:
  1. report back to us what happened,
  2. thank people who gave you working suggestions, or
  3. explain what you got and how that was different from what you were trying to do.
And, if you got something that works, but you can't figure out how it works, ask questions. Most of the volunteers who make suggestions here are happy to explain what their (or someone else's) code does. We want to help you learn how to make the most out of the tools that are available to you.

And, for other people reading this thread. If you wanted to do something like what was requested here on a system that doesn't have gawk and has a date utility that doesn't support the --date option, but you do have access to a 1993 or later version of the Korn shell (such as on Mac OS/X), you could also try:
Code:
#!/bin/ksh
while read d t v
do	printf '%s %-23s%-14s%(%A)T\n' "$d" "$t" "$v" "$d"
done < output

which with the given sample input file produces:
Code:
07/01/14 15:47:22               179.9500      Tuesday
07/01/14 16:03:29               3.9500        Tuesday
06/26/14 11:59:43               19.8000       Thursday
06/27/14 12:02:43               160.0000      Friday
07/02/14 13:12:35               5.9500        Wednesday
07/02/14 13:34:17               5.9500        Wednesday

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the week's day

Hi All, I have the below requirement , if i give the week number for ex 41 i need to get the date for Monday and thursday for this given week. my expected output is 13/10/2014 (Monday's date) and 16/10/2014 (Thursday's date) I am using GNU LINUX . Pls help me with your thoughts. Thanks in... (7 Replies)
Discussion started by: mohanalakshmi
7 Replies

2. UNIX for Dummies Questions & Answers

Sudoers for one day per week?

I have been volunteered by my boss to be the sysadmin for our production redhat server. He asked me to tighten the security to avoid mishaps like "rm -f *" that occured not long ago. Right now, we have 53 users sudo-ing into the machine and it is an audit nightmare. I am wondering if it... (15 Replies)
Discussion started by: alan
15 Replies

3. HP-UX

Find Day of Week

In HP-UX the date command does not have the "-d" switch like some other *nixes do. I'm working a simple script to tell me, given the day, month and year what day of the week that falls on. Assuming valid day, month and year input (I'd perform quality checks on the input separately, but not... (5 Replies)
Discussion started by: rwuerth
5 Replies

4. UNIX and Linux Applications

How to find 'Day of week' in Linux system

Hi All, I want to find a day of week for the Linux system. can some one help me on this.. Thanks in advance, Raji. (2 Replies)
Discussion started by: rajinavaneethan
2 Replies

5. HP-UX

Get Day of Week from date

Hi All, I have date in string format 'YYYY-MM-DD'. I want to know day of the week for this date. Example. For '2005-08-21' my script should return '0' or Sunday For '2005-08-22' it should return '1' or Monday I want piece of code for HP-UX korn shell. Appreciate reply on this. (5 Replies)
Discussion started by: vpapaiya
5 Replies

6. UNIX for Dummies Questions & Answers

How to find Day of the Week from the given date (Perl)?

How to find the Day of the Week of the given Date using perl? If I have a date in YYY--MM-DD format, how to find the DOW? Based on that, I need to find the following sunday. Pls help. (5 Replies)
Discussion started by: deepakwins
5 Replies

7. UNIX for Dummies Questions & Answers

Changing First Day Of The Week?

Hi All, Our system is running on Solaris 8 and we are using US locale. By default the First Day Of Week is Sunday, is it possible for us to change it to Monday? I have googled it but found very little of use. THanks in advance. (2 Replies)
Discussion started by: fowlerleftfoot
2 Replies

8. Shell Programming and Scripting

Yesterday's Day of week

I need o get yesterday's day of week but im not exactly sure. the actual name is what i want. I can do it with numbers but im not sure with words. (3 Replies)
Discussion started by: rcunn87
3 Replies

9. Programming

Function that gets the day of the week (0-6) ??

Hi , I am working at Unix system,using c lang. I need c fun which return the day of the week . For example : 0- Sunday. 1- Monday. .... 10x. (4 Replies)
Discussion started by: kamil
4 Replies

10. UNIX for Dummies Questions & Answers

Calculating the day of the week

Hi all, I would like to calculate the day of the week using a supplied date. i.e. 20011012 = Day 5. Any ideas? Many thanks, ligs (4 Replies)
Discussion started by: ligs
4 Replies
Login or Register to Ask a Question