Saturday, 15 May 2010

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


I am trying to work on the following sample data:

  Amanda, 1.00 , 1418691511, Non-technical, v1 Charles, 7.051417093994, Technical, v1 Christopher, 7.00,1417102400, Technical, V2 David, 4.001417093447, Non-technical, v1 John, 4.75,1417059582, Technical, v1 John, 7.80 , 1417102602, Technical, V2 Yusuf, 7.80,1417093804, Technical, v1 Yusuf, 5.00,1423504662, Technical, V2 Michael, 7.551417092924, Technical, v1 Richard, 5.00,1417093649, non-technical, v1 robert, 3.00, 1417092640, non-technical, v1 Thomas, 6.75,1417102170, technical, v1 Yum, 4.50,1417093255, non-technical, v1th, 2.00,1426017161, technical, v8th, 2.75,1426449217, technical, v9  

Here the third column in csv is the date of the personal records The format is timestamp.

I want to remove data that is time stamp between today and the last 3 days only.

The following I used to get it, but it is not working for me.

  awk -F, '{if ($ 3> = System ("date +% s - dd =" 3 days ago "" ") & amp; $ 3 & Lt; = System ("date +% s")) {print}} ' 

Can you understand what was wrong here?

< P>

Double quotes do not work as you want in this command:

  awk -F, {If ( $ 3 & gt; = system ("date +% s --date =" 3 days ago "") and $ 3 & lt; = system ("date +% s")) {print}} '^ ^  

Two pointers cause problems for people.

I should probably use it:

  awk -F, - V old = $ (Date +% s --date = "3 days ago") -v New = $ (date + s) \ 'if if ($ 3 = = in year & amp; $ 3 & lt; = New} print} ''  

or even:

  awk -F, -v old = $ (date +% s - date = "3 days ago") -v new = $ (date + s) \ '$ 3> = old & amp; $ 3 & lt; = new'  

There are times when system is required, but try to treat it as a 'bad smell'. Usually, if you think carefully, then it is not really necessary.


No comments:

Post a Comment