Csv

在單個列中顯示日期和時間

  • October 30, 2020

我正在使用氣候數據運算符從 NetCDF 中提取時間序列數據。它可以選擇分別提取日期和時間。我用過

cdo -outputtab,date,time,value -remapnn,lon=-85.25_lat=31.57  -select,name=pr pr.sample.nc> out1.csv

但是,我想將此日期和時間合併到一個列中。

在此處輸入圖像描述

這是我的 input.csv https://drive.google.com/drive/folders/1C7XWGXafu1coNICK55AA-GzdM9DqnbuA?usp=sharing

如果它的 CSV :

你可以使用awk,如果它有效,試試這個:

awk 'FNR==1{ row=$2","$3$4","$5;print row  } FNR!=1{ row=$1","$2$3","$4; print row}' input.csv

如果您的輸入文件已連結,則它不是以csv空格分隔的

#    name       date     time    value 
     pr  2006-01-01 12:00:00 0.002509068 
     pr  2006-01-02 12:00:00 0.8440843 
     pr  2006-01-03 12:00:00 0.3695453 
     pr  2006-01-04 12:00:00 6.589583 
     pr  2006-01-05 12:00:00 16.20289 
     pr  2006-01-06 12:00:00 0.1449011 
     pr  2006-01-07 12:00:00 29.98764 
     pr  2006-01-08 12:00:00 18.44757

awk 'BEGIN{OFS=","}
 NR==1{print $2,$3"-"$4,$5}
 NR>1{split($2,d,"-");print $1, int(d[2])"/"d[3]"/"d[1]$3, $4}' input.csv

會給你

name,date-time,value
pr,1/01/200612:00:00,0.002509068
pr,1/02/200612:00:00,0.8440843
pr,1/03/200612:00:00,0.3695453
pr,1/04/200612:00:00,6.589583
pr,1/05/200612:00:00,16.20289
pr,1/06/200612:00:00,0.1449011
pr,1/07/200612:00:00,29.98764
pr,1/08/200612:00:00,18.44757

帶有日期split並根據png

當重定向到> out.csv此時,將根據png

引用自:https://unix.stackexchange.com/questions/595073