Sponsored Content
Top Forums Shell Programming and Scripting Reading text file and comparing the dates in Kshell Post 302353825 by Pramodini Rode on Wednesday 16th of September 2009 10:04:38 AM
Old 09-16-2009
Reading text file and comparing the dates in Kshell

I have a text file in which holidays are listed as YYYYMMDD. Here is the sample data of the file.

20090911
20090912
20090913

I need to read this file and see if the current day is listed in this text file. If today and any of the rows in my text file match, I need to do further processing. I am not sure how to compare the current day with the data from my text file. The code below is not working well as it Prints “today is a holiday”. I know this piece of code is working

(if $(date "+%G%m%d") = ${line_by_line})

Can someone help me with this? Please see my code below.

Thanks.

Pramodini

#!/usr/bin/ksh
. ~/.profile

while read line_by_line

do

if $(date "+%G%m%d") = ${line_by_line}
then
print "Today is not a holiday"
else
print "Today is a holiday"
fi

done < holidays.txt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing 2 dates

hi , I have two variables both containg dates, x= `date` and y= `date' their format being -> Fri Nov 12 22:59:50 MST 2004 how do I compare which one is greater. ->Can dates be converted into integer and then compared? ( one lengthy way would be to compare the words one by... (7 Replies)
Discussion started by: k_oops9
7 Replies

2. Programming

comparing dates

hi is there a c function in linux for comparing dates. thanx in advance. svh (2 Replies)
Discussion started by: svh
2 Replies

3. Shell Programming and Scripting

Comparing two dates

Hi, Can some one guide me how to compare two dates in unix. TIA Gupta (5 Replies)
Discussion started by: guptan
5 Replies

4. Shell Programming and Scripting

comparing dates

Hi guys I have a a variable called check_ts which holds a date value. this date value keeps refreshing every 15 minutes. I am going to start a cron job 5 minutes after the refresh. I have to check if the current date > 20 min of check_ts. how do i do that. thanks ragha (17 Replies)
Discussion started by: ragha81
17 Replies

5. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

6. UNIX for Dummies Questions & Answers

comparing two dates.

Hi I have yesterday date and todays date stored in two variables. Today date is stored in variable -- testdate=`date +%m/%d/%Y` I found the yesterday date and stored in variable -- ydate=$month'/'$day1'/'$year Now i am trying to find out whether $testdate is less that $ydate. I am... (6 Replies)
Discussion started by: intiraju
6 Replies

7. Shell Programming and Scripting

dealing with dates in a text file

hi guys im trying to write a bash script that grabs expired domain names it leaves me with the following outpiut in a text file Im hoping to try to normalise all the dates to the format displayed in the first 2 lines and remove the times so the file looks unfirom can any one give me a... (9 Replies)
Discussion started by: dunryc
9 Replies

8. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

9. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

10. Shell Programming and Scripting

Reading and Comparing values of file

Hi gurus.. Am reading a file, counting number of lines and storing it in a variable. Then am passing that variable into If loop for comparision, if the number of lines are greater than 1000 it should split a file if not it should send the file name to archive folder.. but when i execute the... (4 Replies)
Discussion started by: azherkn3
4 Replies
calendar(1)						      General Commands Manual						       calendar(1)

Name
       calendar - calendar reminder service

Syntax
       calendar [-]

Description
       The  command  consults the file `calendar' in the current directory and prints out lines that contain today's or tomorrow's date.  The com-
       mand recognizes most month-day dates, such as Dec. 7, december 7, 12/7, but it does not recognize dates formatted in the following ways:  7
       December  or  7/12.  If you give the month as * with a date, such as, * 1, that day in any month will do.  On weekends, specifying tomorrow
       extends through Monday.

       When an argument is present, the command searches through a user's calendar file in his login directory and sends him any positive  results
       by Normally this is done daily under control of

       The  calendar  file  is	first  run  through  the  C  preprocessor, to include any other calendar files specified with the #include syntax.
       Included calendars are shared by all users, and are maintained and documented by the local administration.

Options
       -    Functions for every user who has a calendar file in his login directory.

Restrictions
       The extended idea of tomorrow does not account for holidays.

Files
       calendar
       /usr/lib/calendar to figure out today's and tomorrow's dates
       /etc/passwd
       /tmp/cal*
       /lib/cpp, egrep, sed, mail as subprocesses

See Also
       at(1), cron(8), mail(1)

																       calendar(1)
All times are GMT -4. The time now is 10:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy