Page tree

GRIB-API support is being discontinued at the end of 2018. Please consider upgrading to ecCodes

Skip to end of metadata
Go to start of metadata


Copies the content of GRIB files printing values of some keys.


grib_copy [options] grib_file grib_file ... output_grib_file


Force. Force the execution not to fail on error.

Repack data. Sometimes after setting some keys involving properties of the packing algorithm a repacking of data is needed. This repacking is performed setting this -r option.

-p key[:{s/d/l}],key[:{s/d/l}],...
Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string.

-P key[:{s/d/l}],key[:{s/d/l}],...
As -p adding the declared keys to the default list.

-w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]=value,...
Where clause. Only grib messages matching the key/value constraints are copied to the output_grib_file.
A valid constraint is of type key=value or key!=value.
For each key a string (key:s) or a double (key:d) or a long (key:l) type can be defined. Default type is string.
In the value you can also use the forward-slash character "/" to specify an OR condition (i.e. a logical disjunction)

-B order by directive
Order by. The output will be ordered according to the "order by" directive. For example: "step:i asc, centre desc" (step numeric ascending and centre descending)


-W width
Minimum width of each column in output. Default is 10.

Multi-field support off. Turn off support for multiple fields in single grib message.

-T T | B
Message type. T->GTS, B->BUFR. The input file is interpreted according to the message type.

Copy GTS header.

GRIBEX compatibility mode.

Does not fail when the message has wrong length


grib_copy examples

  1. To copy only the pressure levels from a file

    > grib_copy -w levtype=pl ../data/tigge_pf_ecmwf.grib2 out.grib
  2. To copy only the fields that are not on pressure levels from a file

    > grib_copy -w levtype!=pl ../data/tigge_pf_ecmwf.grib2 out.grib
  3. To copy only the first three fields from a file

    > grib_copy -w count=1/2/3 ../data/tigge_pf_ecmwf.grib2 out.grib
  4. A grib_file with multi field messages can be converted in single field messages with a simple grib_copy

    > grib_copy multi.grib simple.grib
  5. Use the square brackets to insert the value of a key in the name of the output file (This is a good way to split a large GRIB file)
    Note: we need to quote the name of the output so the shell does not interpret the square brackets

    > grib_copy in.grib 'out_[shortName].grib'
  6. To copy fields whose typeOfLevel is either "surface" or "meanSea"

    > grib_copy -w typeOfLevel=surface/meanSea orig.grib out.grib
  7. To copy selected fields and apply sorting (sorted by level in ascending order)
    Note: we need to specify the ":i" to get a numerical sort. By default values are sorted as strings so a level of 100 would come before 20!

    > grib_copy -w typeOfLevel=heightAboveGround -B"level:i asc" tigge_af_ecmwf.grib2 out.grib




  • No labels