Usando awk
para análise e date
para formatar a data, o que mais ;)
awk 'BEGIN {printf "%s\t%s\t%s\n","YYYY","DDD","sim"} NR != 1 {system("date -d \""$2"\" +\"%Y\t%-d\t"$3"\"")}' your_file
Para mostrar o dia do ano (usando %j
em vez de %d
ou melhor %-j
em vez de %-d
, o -
evita 0
)
awk 'BEGIN {printf "%s\t%s\t%s\n","YYYY","DDD","sim"} NR != 1 {system("date -d \""$2"\" +\"%Y\t%-j\t"$3"\"")}' your_file
Exemplo
O arquivo de entrada
% cat foo
ID date DailyFlow
a 1972-01-01 17.0265761797993
b 1972-01-02 17.200476457399
c 1972-01-03 17.2926436045271
d 1972-01-04 17.3900277599829
e 1972-01-05 17.5987080931028
f 1972-01-06 17.6334881486229
g 1972-01-07 17.7030482596626
h 1972-02-01 17.7030482596626
i 1972-02-02 17.7030482596626
A saída (com o dia do mês)
% awk 'BEGIN {printf "%s\t%s\t%s\n","YYYY","DDD","sim"} NR != 1 {system("date -d \""$2"\" +\"%Y\t%-d\t"$3"\"")}' foo
YYYY DDD sim
1972 1 17.0265761797993
1972 2 17.200476457399
1972 3 17.2926436045271
1972 4 17.3900277599829
1972 5 17.5987080931028
1972 6 17.6334881486229
1972 7 17.7030482596626
1972 1 17.7030482596626
1972 2 17.7030482596626
A saída (com o dia do ano)
% awk 'BEGIN {printf "%s\t%s\t%s\n","YYYY","DDD","sim"} NR != 1 {system("date -d \""$2"\" +\"%Y\t%-j\t"$3"\"")}' foo
YYYY DDD sim
1972 1 17.0265761797993
1972 2 17.200476457399
1972 3 17.2926436045271
1972 4 17.3900277599829
1972 5 17.5987080931028
1972 6 17.6334881486229
1972 7 17.7030482596626
1972 32 17.7030482596626
1972 33 17.7030482596626