Extract data between epoch times in a csv using shell script -


i'm trying work on following sample data:

amanda,1.00,1418691511,non-technical,v1 charles,7.05,1417093994,technical,v1 christopher,7.00,1417102400,technical,v2 david,4.00,1417093447,non-technical,v1 john,4.75,1417059582,technical,v1 john,7.80,1417102602,technical,v2 joseph,7.80,1417093804,technical,v1 joseph,5.00,1423504662,technical,v2 michael,7.55,1417092924,technical,v1 richard,5.00,1417093649,non-technical,v1 robert,3.00,1417092640,non-technical,v1 thomas,6.75,1417102170,technical,v1 william,4.50,1417093255,non-technical,v1 rd,2.00,1426017161,technical,v8 rd,2.75,1426449217,technical,v9 

here third column in csv epoch date format timestamp of individual records.

i want extract data has time stamp between today , past 3 days only.

following used achieve doesn't seem working me.

awk -f , '{if ($3 >= system("date +%s --date="3 days ago"") && $3 <= system("date +%s")) { print }}' 

can me in understanding went wrong here?

the double quotes in command not work want them to:

awk -f , '{if ($3 >= system("date +%s --date="3 days ago"") && $3 <= system("date +%s")) { print }}'                                              ^          ^ 

the 2 marked ones cause trouble.

i'd use:

awk -f, -v old=$(date +%s --date="3 days ago") -v new=$(date +s) \     '{ if ($3 >= old && $3 <= new) print }' 

or even:

awk -f, -v old=$(date +%s --date="3 days ago") -v new=$(date +s) \     '$3 >= old && $3 <= new' 

there times when system necessary, try treat 'bad smell'. usually, not necessary if think carefully.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -