Reputation: 55
I used Climate data operator (CDO) to extract time series in CSV format with the following code
cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc> output.csv
Here, CSV file comes with variables date, lon, lat and value in a single column as shown below.
date lat lon value
1950-01-01 31.57 -85.25 0.05
1950-01-01 31.57 -85.25 0.06
1950-01-01 31.57 -85.25 0.07
.......
.......
2000-01-01 31.57 -85.25 3.01
How can I create a column for each variable?
If possible, I want to change in the given code.
Upvotes: 1
Views: 976
Reputation: 55
I am not sure whether it's a good way to answer myself as I don't want to delete my question.I want to attached my answer as I am able to solve by using the following code
cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc | awk 'FNR==1{ row=$2","$3","$4","$5;print row } FNR!=1{ row=$1","$2","$3","$4; print row}' > output.csv
Upvotes: 1
Reputation: 52439
Use sed
to turn the spaces into commas?
Something like
cdo -outputtab,date,lon,lat,value -remapnn,lon={}_lat={} input.nc |
sed 's/[[:space:]]/,/g' > output.csv
(This will also work if cdo
uses tabs instead of spaces to separate values).
Upvotes: 1