dealing with dates in a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dealing with dates in a text file
# 1  
Old 03-20-2012
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

Quote:
1, test.com Expiration Date:17-jun-2013
2, test.net Expiration Date:29-mar-2013
3, test.org Expiration Date:26-Jul-2012 04:00:00
4, .test.biz Expiration Date:Mar 26 23:59:59 2012
5, test.info Expiration Date:27-Jul-2012 07:56:43

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 heads up ?

Thanks for looking

Last edited by dunryc; 03-20-2012 at 02:37 PM..
# 2  
Old 03-20-2012
Code:
#!/bin/bash

while IFS=":" read THING TIME
do
        set -- $TIME

        case "$TIME" in
        [0-9][0-9]-???-[0-9][0-9][0-9][0-9])    ;;
        [0-9][0-9]-???-[0-9][0-9][0-9][0-9]" "*)
                TIME=$1
                ;;
        [jJ]an" "*|[fF]eb" "*|[mM]ar" "*|[aA]pr" "*|[mM]ay" "*|[jJ]un" "*|[jJ]ul" "*|[aA]ug" "*|[sS]ep" "*|[oO]ct" "*|[nN]ov" "*|[dD]ec" "*)
                TIME=$(printf "%02d-%s-%04d\n" $2 $1 $4)
                ;;
        *)
                echo "Unknown time format $TIME" >&2
                continue
                ;;
        esac

        echo "$THING:$TIME"
done < data

# 3  
Old 03-20-2012
@corona688 much apprectiaed worked like a charm

thanks
# 4  
Old 03-20-2012
You can use date itself to perform this,

Code:
$ for i in \
  "17-jun-2013" \
  "29-mar-2013" \
  "26-Jul-2012 04:00:00" \
  "Mar 26 23:59:59 2012" \
  "27-Jul-2012 07:56:43" ; \
do \
  date -d "$i" '+%d-%b-%Y' ; \
done ;
17-Jun-2013
29-Mar-2013
26-Jul-2012
26-Mar-2012
27-Jul-2012

# 5  
Old 03-20-2012
When someone hasn't stated what their system is, odds are good an answer using GNU date will be useless; you don't find that mostly anywhere except Linux. Only fairly recent versions of GNU date have a -d that flexible, too.
# 6  
Old 03-20-2012
Quote:
Originally Posted by Corona688
When someone hasn't stated what their system is, odds are good an answer using GNU date will be useless; you don't find that mostly anywhere except Linux. Only fairly recent versions of GNU date have a -d that flexible, too.
When I find that date can't do things like this I often just build GNU Coreutils on the destination. The time it takes to compile is often far less than tweaking to get the date handling right myself Smilie
# 7  
Old 03-20-2012
So would I, on any machine I had administrator oversight on. But that's often a limitation too Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Sum duplicate values in text file through awk between dates

I need to sum values in text file in case duplicate row are present with same name and different value below is example of data in file i have and format i need. Data in text file 20170308 PM,U,2 PM,U,113 PM,I,123 DA,U,135 DA,I,113 DA,I,1 20170309 PM,U,2 PM,U,1 PM,I,123 PM,I,1... (3 Replies)
Discussion started by: Adfire
3 Replies

3. Emergency UNIX and Linux Support

Dealing with XLS file with multiple tabs

Hey Guys , Recently working on a requirement , i had to deal with XLS file with multiple tabs and the requirement was as below : 1. Convert one XLS file with multiple tabs to multiple CSV files. -- As i was working on MAC , so it was quite easy through APPLESCRIPT to deal with this.But... (6 Replies)
Discussion started by: himanshu sood
6 Replies

4. UNIX for Advanced & Expert Users

Shell script for dealing with XLS file with multiple tabs/worksheets

Hey Guys , Recently working on a requirement , i had to deal with XLS file with multiple tabs and the requirement was as below : 1. Convert one XLS file with multiple tabs to multiple CSV files. -- As i was working on MAC , so it was quite easy through APPLESCRIPT to deal with this.But... (2 Replies)
Discussion started by: himanshu sood
2 Replies

5. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

6. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

Dealing with spaces in file names in a shell script

Hi, What's the best way to find all files under a directory - including ones with space - in order to apply a command to each of them. For instance I want get a list of files under a directory and generate a checksum for each file. Here's the csh script: #!/bin/csh set files = `find $1... (5 Replies)
Discussion started by: same1290
5 Replies

10. Shell Programming and Scripting

building text file with calendar dates

Can somebody help me in building a text file which will contain the dates of 2 yrs in the format YYYYMMDD using korn shell e.g. to generate a file with the contents 20010101 20010102 ... ... 20010131 20010201 ... ... 20010228 20010301 ... and so on. (2 Replies)
Discussion started by: rkkiran
2 Replies
Login or Register to Ask a Question