Calculate date difference between $2,$3 from file in awk

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Calculate date difference between $2,$3 from file in awk

k3090

File with only date,

file.txt

    P1,2013/jul/9,2013/jul/14
    P2,2013/jul/14,2013/jul/6
    P3,2013/jul/7,2013/jul/5

display output like this

    P1,2013/jul/9,2013/jul/14,5days
    P2,2013/jul/14,2013/jul/6,8days
    P3,2013/jul/7,2013/jul/5,2days
Reply | Threaded
Open this post in threaded view
|

Re: Calculate date difference between $2,$3 from file in awk

Guru
Administrator
You can refer the last example in this article to get started with this: Date calculations using gawk

 In your case, since the month is specified in words, you need to get it converted to the month number. You can create a file which contains the mapping for the month and number as below:

jan 0
feb 1

  Replace your month with the month number, and for the rest the last example should help.