<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Comparing Dates within files in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823193#M100417</link>
    <description>Okay, now that the problem is better defined I would leverage find, awk, and caljd.sh to handle this task (I'll assume that your homedirs are located in /home):&lt;BR /&gt;&lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset FNAME=".datefile"&lt;BR /&gt;typeset -i MAXDAYS=90&lt;BR /&gt;&lt;BR /&gt;typeset F=""&lt;BR /&gt;typeset MO=""&lt;BR /&gt;typeset DAY=""&lt;BR /&gt;typeset YEAR=""&lt;BR /&gt;&lt;BR /&gt;typeset -i TODAY=$(caljd.sh)&lt;BR /&gt;find /home -type f -name "${FNAME}" 2&amp;gt;/dev/null | while read F&lt;BR /&gt;  do&lt;BR /&gt;    awk '{if ($0 ~ "[0-9]{8}") {print substr($0,1,2),substr($0,3,2),substr($0,5)}}' "${F}" | read DAY MO YEAR&lt;BR /&gt;    if [[ -n "${YEAR}" ]] # only need to test YEAR; if not null the 1st 2&lt;BR /&gt;                          # read variables can't be null&lt;BR /&gt;      then&lt;BR /&gt;        typeset -i FDAY=$(caljd.sh -e ${DAY} ${MO} ${YEAR})&lt;BR /&gt;        typeset -i AGE=$((${TODAY} - ${FDAY}))&lt;BR /&gt;        if [[ ${AGE} -gt ${MAXDAYS} ]]&lt;BR /&gt;          then&lt;BR /&gt;            echo "Age: ${AGE} days Homedir: $(dirname ${F})"&lt;BR /&gt;          fi&lt;BR /&gt;      fi&lt;BR /&gt;  done &lt;BR /&gt;             &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------------------&lt;BR /&gt;&lt;BR /&gt;If I didn't make no typing booboo's that should do it and be rather robust as well.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You will also need the caljd.sh script; attached is the latest version; make it executable and place somewhere in your PATH&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 14 Jul 2006 09:36:49 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-07-14T09:36:49Z</dc:date>
    <item>
      <title>Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823186#M100410</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a number of files listed in certain users home directories (/home/username/) on one of my unix boxes and within this file the date is displayed in number format - 26062006.&lt;BR /&gt;&lt;BR /&gt;I would like to create a script that would check the date within these files and if the date is older than X no. of months the script would then display the username from the home directory path.&lt;BR /&gt;&lt;BR /&gt;Im stuck with this as ive not found out a way of comparing dates and finding out if the date is older than 3 months.&lt;BR /&gt;&lt;BR /&gt;Does anyone have any pointers or perhaps have created something similar in the past and could show me what they've done.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Thu, 13 Jul 2006 10:33:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823186#M100410</guid>
      <dc:creator>Lloydy</dc:creator>
      <dc:date>2006-07-13T10:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823187#M100411</link>
      <description>Hi,&lt;BR /&gt;please have a look at threads:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1040167" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1040167&lt;/A&gt;&lt;BR /&gt;and&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1028348" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1028348&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jul 2006 10:47:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823187#M100411</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-07-13T10:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823188#M100412</link>
      <description>The difficultly stems from your lack of precision of the term "older than 3 months". For example, what does it mean on 28-May on a leapyear? It's quite easy if you change your 3 months to older than 90 days for example because that has an exact meaning.&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jul 2006 10:47:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823188#M100412</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-07-13T10:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823189#M100413</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;1) I think it is not important for you to match the 3 month correctly - this timeframe differs in some days depending on the current day of the year.&lt;BR /&gt;&lt;BR /&gt;2) You do not tell us much about how the date is located in the files you want to analyze:&lt;BR /&gt;- files are textfiles?&lt;BR /&gt;- datespecifier single on a line?&lt;BR /&gt;- what pattern (if any?) comes after the datespefifier?&lt;BR /&gt;- may there be multiple matches?&lt;BR /&gt;- is the first match of '- DATEPATTERN' the one you are looking for or the last or ...?&lt;BR /&gt;&lt;BR /&gt;My assuptions:&lt;BR /&gt;- textfiles&lt;BR /&gt;- not single on a line&lt;BR /&gt;- space after datespec.&lt;BR /&gt;- first match&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Lets look ...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Thu, 13 Jul 2006 10:56:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823189#M100413</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-07-13T10:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823190#M100414</link>
      <description>A. Clay Stephenson:&lt;BR /&gt;&lt;BR /&gt;90 days would be fine.  Because thats near enough 3 months.&lt;BR /&gt;&lt;BR /&gt;Peter Nikitka:&lt;BR /&gt;&lt;BR /&gt;The files are titled .datefile and sit in some users home directories... not all.  So yes there could be multiple .datefiles but each users home directory would only have 1 of these files at the most.&lt;BR /&gt;&lt;BR /&gt;There is basically nothing in this file apart from a single date string of text... e.g. 260702006 &lt;BR /&gt;&lt;BR /&gt;Nothing else sits in that file whatsoever.&lt;BR /&gt;&lt;BR /&gt;find /home/. -name .datefile|cut -d / -f 4 &amp;gt; /home/adam/found.txt&lt;BR /&gt;&lt;BR /&gt;The above writes all the users with the datefile to a new file.  I guess its then a matter of comparing the date in all theses users datefiles to see if the date is older than 90 days.  If so write them to another text file and/or display them on screen.&lt;BR /&gt;&lt;BR /&gt;Unfortunantly this is where I become stuck.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jul 2006 04:21:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823190#M100414</guid>
      <dc:creator>Lloydy</dc:creator>
      <dc:date>2006-07-14T04:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823191#M100415</link>
      <description>Hi,&lt;BR /&gt;as per my earlier post:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read record&lt;BR /&gt;do&lt;BR /&gt;a=`echo $record | cut -c0-2`&lt;BR /&gt;b=`echo $record | cut -c3-4`&lt;BR /&gt;c=`echo $record | cut -c5-8`&lt;BR /&gt;FileJD=`./caljd.sh -e $a $b $c`&lt;BR /&gt;NowJD=`./caljd.sh`&lt;BR /&gt;days=`expr $NowJD - $FileJD`&lt;BR /&gt;if [ $days -ge 90 ]&lt;BR /&gt;then&lt;BR /&gt;echo $record more than 90 days old&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; a.lis&lt;BR /&gt;&lt;BR /&gt;Reads a file (a.lis) line by line and takes the date in format DDMMYYY, works out the Julian date and then establishes the number of days between todays julian date and the record date. If it is greater or equal to 90 days it prints the input record.&lt;BR /&gt;&lt;BR /&gt;For this to work, you will need the caljd.sh script that is available for free at the locations mentioned in the referenced threads.</description>
      <pubDate>Fri, 14 Jul 2006 05:18:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823191#M100415</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-07-14T05:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823192#M100416</link>
      <description>&lt;!--!*#--&gt;OK,&lt;BR /&gt;&lt;BR /&gt;try this:&lt;BR /&gt;&lt;BR /&gt;awk -v now=$(date +%Y%m%d) 'function days(str) { num=(substr(str,5,2)-1)*30+substr(str,7)&lt;BR /&gt;str-=20000000&lt;BR /&gt;num+=substr(str,1,length(str)-4)*365&lt;BR /&gt;return num}&lt;BR /&gt;BEGIN { today=days(now) }&lt;BR /&gt;FILENAME != lastfile &amp;amp;&amp;amp; $0 ~ "^[0-9][0-9]*$" {fdays=days($0)&lt;BR /&gt;if ((today-fdays) &amp;gt; 90) print FILENAME;lastfile=FILENAME}' file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;Notes:&lt;BR /&gt;- I count every month to 30days, a year to 365days&lt;BR /&gt;- starting year is 2000&lt;BR /&gt;- every file is used once AND if the first file scontains only digits&lt;BR /&gt;- you can put this awk in file 'datecmp' and call&lt;BR /&gt;find ... | xargs datecmp.awk&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Fri, 14 Jul 2006 06:21:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823192#M100416</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-07-14T06:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823193#M100417</link>
      <description>Okay, now that the problem is better defined I would leverage find, awk, and caljd.sh to handle this task (I'll assume that your homedirs are located in /home):&lt;BR /&gt;&lt;BR /&gt;-----------------------------------------&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset FNAME=".datefile"&lt;BR /&gt;typeset -i MAXDAYS=90&lt;BR /&gt;&lt;BR /&gt;typeset F=""&lt;BR /&gt;typeset MO=""&lt;BR /&gt;typeset DAY=""&lt;BR /&gt;typeset YEAR=""&lt;BR /&gt;&lt;BR /&gt;typeset -i TODAY=$(caljd.sh)&lt;BR /&gt;find /home -type f -name "${FNAME}" 2&amp;gt;/dev/null | while read F&lt;BR /&gt;  do&lt;BR /&gt;    awk '{if ($0 ~ "[0-9]{8}") {print substr($0,1,2),substr($0,3,2),substr($0,5)}}' "${F}" | read DAY MO YEAR&lt;BR /&gt;    if [[ -n "${YEAR}" ]] # only need to test YEAR; if not null the 1st 2&lt;BR /&gt;                          # read variables can't be null&lt;BR /&gt;      then&lt;BR /&gt;        typeset -i FDAY=$(caljd.sh -e ${DAY} ${MO} ${YEAR})&lt;BR /&gt;        typeset -i AGE=$((${TODAY} - ${FDAY}))&lt;BR /&gt;        if [[ ${AGE} -gt ${MAXDAYS} ]]&lt;BR /&gt;          then&lt;BR /&gt;            echo "Age: ${AGE} days Homedir: $(dirname ${F})"&lt;BR /&gt;          fi&lt;BR /&gt;      fi&lt;BR /&gt;  done &lt;BR /&gt;             &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------------------&lt;BR /&gt;&lt;BR /&gt;If I didn't make no typing booboo's that should do it and be rather robust as well.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You will also need the caljd.sh script; attached is the latest version; make it executable and place somewhere in your PATH&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jul 2006 09:36:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823193#M100417</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-07-14T09:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Dates within files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823194#M100418</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;did you get successful hints with the presented solutions?&lt;BR /&gt;Was something wrong?&lt;BR /&gt;&lt;BR /&gt;Look at&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;as well.</description>
      <pubDate>Mon, 17 Jul 2006 07:06:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/comparing-dates-within-files/m-p/3823194#M100418</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-07-17T07:06:27Z</dc:date>
    </item>
  </channel>
</rss>

