Reputation: 437
Can't seem to find a solid similar question. In basic terms, I'm just trying to perform an action to multiple files but I struggle with for loops. I want to ncdump multiple files at once and store the output in separate files. This is what I have so far.
#!/bin/bash
date='20160503'
dump1Dir=/server1/applications/VAL/gran_files
cd $dump1Dir
filelist=`ls *s$date*`
for i in $filelist do
ncdump $filelist > dumpfile[i]
done
Upvotes: 0
Views: 573
Reputation: 146
This should work as well (assuming source file has .nc extension, and output is using .cdf)
cd $dump1Dir
ls -1 *s$date*.nc | while read file; do ncdump "$file" > "${file%.nc}.cdf"; done
Upvotes: 0
Reputation: 241701
I think that what you want is something like:
for file in *s$date*.nc; do ncdump "$file" > "${file%.nc}.cdf"; done
but that includes a bunch of assumptions.
What it will do is:
.nc
, and includes an s
followed by the value of the variable $date
ncdump
to create a file with the same name, changing the extension from nc
to cdf
Upvotes: 4