Valid date checking in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Valid date checking in the file
# 1  
Old 11-01-2011
Valid date checking in the file

File contian below data...

20111101
20111102
20111131
I am new to unix and per scirpt...
First two records are valid and last record is invalid,how to get the valid records...
Please help me unix or perl script.

Smilie

Thanks,
Murali
# 2  
Old 11-01-2011
Code:
while read line
do 
  date -d "$line" >/dev/null 2>&1 && echo $line 
done < input_file

--ahamed
# 3  
Old 11-01-2011
Code:
#!/bin/perl
use Date::Calc;
my($year,$month,$day)=/(\d{4})(\d{2})(\d{2})/;
if (check_date($year,$month,$day)){
   #the date is valid so do stuff
}

# 4  
Old 11-01-2011
Similar implementation using awk
Code:
awk '{cmd="date -d "$0" >/dev/null 2>&1; echo $?"; cmd|getline x} !x' input_file

--ahamed
# 5  
Old 11-01-2011
Great help... Can you give me PERL SCRIPT for date validation...
# 6  
Old 11-01-2011
What's wrong with the Perl script I gave you?
you know that you can add Date::Calc with the following command?
Code:
perl -MCPAN -e 'install Date::Calc;'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Valid separator in time and date format

Hello. I can use any particular (stupid or not) format when using bash date command. Example : ~> date --date "now" '+%Y-%m-%d %H!%M!%S' 2019-06-03 12!55!33or ~> date --date "now" '+%Y£%m£%d %H¤%M¤%S' 2019£06£03 12¤57¤36 or ~> date --date "now" '+%Y-%m-%d %H-%M-%S' 2019-06-03 12-58-51 ... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

Valid and invalid date in the file

Hi All, How to validate the 4th column,it is date column in the file, if it valid move to valid file else moved invalid file. 9f680174-cb87|20077337254|0|20120511|N 9f680174-cb88|20077337254|0|20120534|N i want two file valid.txt and invalid.txt Thanks, (7 Replies)
Discussion started by: bmk
7 Replies

3. UNIX for Dummies Questions & Answers

Short Program for Checking Server date

Hi Guys, Good morning! I have a file which looks something like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server3 Thu Jan 12 11:10:39 EET 2012 ------------------------------------------------... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

4. Shell Programming and Scripting

Checking the total size of all files from a particular date

Hi I have some set of files for a particular date. What is the command that I need to put in for finding the total size of all the files for that particular date. The following command is fetching me the size of all individual files seperately du -h *20101010* 16M file1.20101010 120K... (10 Replies)
Discussion started by: bobby1015
10 Replies

5. Shell Programming and Scripting

Checking for a valid MAC Address

I have a ksh script and would like to validate a MAC address that is input by the user: 00:14:4F:FC:00:49 example: MAC=`/usr/bin/ckint -p "Enter MAC address"` echo $MAC echo " " Obviously chkint will not work, but does anyone have any suggestions? Thanks (9 Replies)
Discussion started by: hxman
9 Replies

6. Shell Programming and Scripting

Need to get next valid date from date string

Hi, I am passing date string of format 'YYYYMMDD' to a ksh script. Will I be able to get next valid date from the passed in string. Example I pass '20100228' to the shell script, Is there a reverse date command to get '20100301' .i.e to convert '20100228' to date and get next date.... (5 Replies)
Discussion started by: bittoo
5 Replies

7. Shell Programming and Scripting

Need help in checking the date and looking for a keyword in a script

Hi, I have a cron process that runs daily and generates a log file. The process writes the date it ran and also any errors to the log file. I need to write a script that will check if the process ran yesterday and also look for the keyword 'ERROR'. If it did not run yesterday or if it found... (0 Replies)
Discussion started by: tatchel
0 Replies

8. UNIX for Dummies Questions & Answers

KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous... (4 Replies)
Discussion started by: developncode
4 Replies

9. Shell Programming and Scripting

checking valid values in variable

I'm using the following in my script. if echo $cpuidle |/usr/bin/egrep ; then when I issue this statement it issues the value of the variable back to stdout which ends up in my output file. Is there a better way to write this? I'm using ksh on solaris 9. (3 Replies)
Discussion started by: MizzGail
3 Replies

10. Shell Programming and Scripting

Checking the valid paths in the shell script

Hi i am using a shell script for renaming the files and placing in the remote location(FTP) my code is: cd $1 day=$(date +%d) for i in `ls -1 BBW*` do last=`tail -1 $i` pat=`expr "$last" : '.*(\(.*\)).*'` pat=`echo $pat | sed 's/ /_/'` pat=$pat$day mv $i $pat rm -f $day done... (3 Replies)
Discussion started by: srivsn
3 Replies
Login or Register to Ask a Question