Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a file delimited with '|' and want to remove all the records from the file if the date is greater than a year from sysdate. The layout of the file is as below -
00719210001800|002555|004027|2009-12-27-00:00| 000000000|N
00719210001800|002555|004027|2010-01-03-00:00| 000000000|N
00719210001800|002555|004027|2010-01-10-00:00| 000000000|N
00719210001800|002555|004027|2010-01-17-00:00| 000000000|NAs you can see above, we need to pick the year, month and day from the timestamp field from the file and do the comparison if if it greater than a year from the current date, then delete that record.
Any pointers/directions is greatly appreciated..
Thanks,
Max

Maybe this korn script will help:
#!/bin/ksh # add 1 to this year newyy=$(( $(date '+%Y') + 1 )) mmdd=$(date '+%m-%d') # build the date chkdate="${newyy}-${mmdd}-00:00" while IFS="|" read f1 f2 f3 fdate therest do if [[ $fdate < $chkdate ]] then echo "${f1}|${f2}|${f3}|${fdate}|${therest}" fi done < datafile.txt

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |