I have a bash script to extract data based on information in one column and I would like to add a date comparison in another column.
below is my file
cat foo
Info1.a ,Info1.b ,yes ,Info1.d ,Info1.e ,Info1.f ,01/01/2011 ,Info1.g Info1.h ,Info1.i ,Info1.j ,Info1.k ,Info1.l
Info2.a ,Info2.b ,no ,Info2.d ,Info2.e ,Info2.f ,02/01/2012 ,Info2.g Info2.h ,Info2.i ,Info2.j ,Info2.k ,Info2.l
Info3a ,Info3.b ,no ,Info3.d ,Info3.e ,Info3.f ,03/01/2013 ,Info3.g Info3.h ,Info3.i ,Info3.j ,Info3.k ,Info3.l
Info4.a ,Info4.b ,yes ,Info4.d ,Info4.e ,Info4.f ,04/01/2014 ,Info4.g Info4.h ,Info4.i ,Info4.j ,Info4.k ,Info4.l
Info5.a ,Info5.b ,yes ,Info5.d ,Info5.e ,Info5.f ,05/01/2015 ,Info5.g Info5.h ,Info5.i ,Info5.j ,Info5.k ,Info5.l
Info6.a ,Info6.b ,no ,Info6.d ,Info6.e ,Info6.f ,06/01/2016 ,Info6.g Info6.h ,Info6.i ,Info6.j ,Info6.k ,Info6.l
Info7.a ,Info7.b ,no ,Info7.d ,Info7.e ,Info7.f ,07/01/2017 ,Info7.g Info7.h ,Info7.i ,Info7.j ,Info7.k ,Info7.l
Info8.a ,Info8.b ,yes ,Info8.d ,Info8.e ,Info8.f ,08/01/2018 ,Info8.g Info8.h ,Info8.i ,Info8.j ,Info8.k ,Info8.l
Info8.a ,Info8.b ,no ,Info8.d ,Info8.e ,Info8.f ,09/01/2019 ,Info8.g Info8.h ,Info8.i ,Info8.j ,Info8.k ,Info8.l
When I run the following command it returns nothing:
awk -F"," -v somedate="01/02/2015" '($3 == "yes" && $7 > somedate)' foo
However when I run the following command it returns some data but not what I am looking for:
sed "s/ //g" foo | awk -F"," -v somedate="01/02/2015" '($3 == "yes" && $7 > somedate)'
Info4.a,Info4.b,yes,Info4.d,Info4.e,Info4.f,04/01/2014,Info4.gInfo4.h,Info4.i,Info4.j,Info4.k,Info4.l
Info5.a,Info5.b,yes,Info5.d,Info5.e,Info5.f,05/01/2015,Info5.gInfo5.h,Info5.i,Info5.j,Info5.k,Info5.l
Info8.a,Info8.b,yes,Info8.d,Info8.e,Info8.f,08/01/2018,Info8.gInfo8.h,Info8.i,Info8.j,Info8.k,Info8.l
I would like to not remove the spaces and I would also like to have it return ony the following lines:
Info5.a ,Info5.b ,yes ,Info5.d ,Info5.e ,Info5.f ,05/01/2015 ,Info5.g Info5.h ,Info5.i ,Info5.j ,Info5.k ,Info5.l
IInfo8.a ,Info8.b ,yes ,Info8.d ,Info8.e ,Info8.f ,08/01/2018 ,Info8.g Info8.h ,Info8.i ,Info8.j ,Info8.k ,Info8.l
Any suggestions would be greatly appreciated.