Categories
Linux Mastering Development

bash script to apply ncrcat on multiple files based on cycle number

I have a simulation model where I can run a simulation in multiple parts, where for each part output is generated with an increasing cycle number. Output files may look like the following:

a.000.nc   b.000.nc  c.000.nc
a.001.nc   b.001.nc  c.001.nc
a.002.nc   b.002.nc  c.002.nc

To concatenate these files, I use nco, more specifically the record concatenator ncrcat. I used to do this manually like the following for each file name (a through c):

ncrcat a.00{0..2}.nc a.nc 

How would I go about writing a bash script that performs the ncrcat command on all files and concatenates all files with increasing cycle number (so a.000.nc, a.001.nc and a.002.nc to a.nc; next file would be b.000.nc, b.001.nc, b.002.nc to b.nc)? I got as far with egrep, etc. to extract which cycle numbers are present in an ls output, but do not know how to extract the file name.

Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *