finding date numeral from file and check the validity of date format
hi there
I have file names in different format as below
Now my this little piece of awk will give me only date from that file name
if name is triss_20111117_fxcb.csv then o/p 20111117 which is perfect
if name is xpnl_hypo_reu_miplvdone_11-17-2011.csv then o/p is 11-17-2011.csv which is not perfect as .csv
if name is xpnl_hypo_reu_miplvdone_20111117xfb.csv then o/p is 20111117xfb.csv
if name is triss_fxcb_20111117.csv.checksum then o/p is 20111117.csv.checksum
question is how to remove .csv or any charcter from the o/p as I only need the date from the filename ?
and once I have the date in format like
how can i validate these date format are valid date. date can be in any of above form.
e.g.
11-17-2011
20111117
11172011
If perl is ok, this is the equivalent for the dates:
And for the validation, you can star with:
Of course you need to adapt the regex to match the rest of the date formats.
thanks KlashXX and Franklin for your suggestion. but unfortunatley I can't use perl in my case .
and I found Frankling sugesstion working for all type of files .
By the mean time I tried below option
which is also works for almost all the conditions except if the filename is
xpnl_hypo_reu_miplvdone_11-17-2011.csv i.e if in any characters are in between then o/p is
can anyone suggest how to improve this liner.I don't care if any - removed between number but atleast it should be numeral in one line not line after another.
anyway can anyone suggest how to validate the date o/p please??
i try to set linux date & time in specific format but it keep giving me error
Example :
date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01"
or
date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01"
keep giving me this error :
date: invalid date ‘19-01-2017 00:05:01'
Please use CODE tags... (7 Replies)
hi All,
i have file in which it has 2000 records like,
test.txt
====
2011-03-01
2011-03-01
2011-03-01
2011-03-01
2011-03-01
2011-03-02
2011/03/02
previously i used for loop to find the date check like below,
for i in `cat test.txt`
do
d=`echo $i | cut -c9-10| sed 's/^0*//'`;... (11 Replies)
Hi Unix Gurus,
I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Hi! how do i know if the input is the same as the required date format? the date should be dd/mm/YYYY ex. 2/3/2012 or 15/11/2012
all the following conditions must return an error:
*input of string
*day is > 31 or < 1
*month is > 12 or < 1
*year is < 2013
suppose the date format is stored... (1 Reply)
Dear all,
I have 2 questions.
I have a file with many rows which has date of the format YYYYMMDD.
1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too.
2. After converting the date to... (10 Replies)
Guys,
I have an input file such as below
I would like to know how i would be able to find items created before 2011-10-01
Appreciate any expert advice. Thanks. (3 Replies)
Hi guys,
I had a scenario...
1. I had to get the previous days date in yyyymmdd format
2. i had to create a file with Date inthe format yyyymmdd.txt format
both are different
thanks guys in advance.. (4 Replies)
how to check input date format.
for example $input_date must be in format dd.mm.gg
script is execute like this:
bin/script1.sh 14.12.2009
script1.sh code:
#!/bin/sh
input_date=$1
CMD="/app/si/test/test.sh $input_date"
echo "*****"
$CMD (2 Replies)
I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column.
I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this?
Sample input
02/27/09,23:52:31
02/27/09,23:52:52... (3 Replies)
Hi,
I have a date field in my input file.
I just want to check if its in the format "DD-MM-YYYY".
Is there any command which can achieve this?
Thanks and Regards,
Abhishek (2 Replies)