Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus,

I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4:

NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~
NETW~US60~000000000013220694~003~~IT~USD~2.23~20110201~99991231~01~01~20111104~
NETW~US60~000000000013234445~001~~IT~USD~0.33~20090107~99991231~01~01~~

Logic would be:

  1. Start reading line @ Row 4.
  2. Check the date of the last column.
  3. If date > current date, delete line
  4. If there is no date, retain line

So from the example above, the record in the middle should be deleted from the file, thus retaining the 1st and 3rd lines.

Much appreciated!
Chumsky

$ today=`date +%Y%m%d`;nawk -F"\~" -v date=$today '{ if( $13 < date) {print $0} }' filename
NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~
NETW~US60~000000000013234445~001~~IT~USD~0.33~20090107~99991231~01~01~~

Thank you very much itkamaraj. This works perfectly, only thing I am missing is how to start reading the file from row 4. Any ideas?

Thanks!

 
today=`date +%Y%m%d`;nawk -F"\~" -v date=$today '{ if(NR >3) { if( $13 < date) {print $0}}}' filename

you are a star! Thank you