extract every filename containing certain string in a directory and do some commend per file

Hi,

Here is my question: suppose I have files like

1990_8xdaily_atmos.nc
1991_8xdaily_atmos.nc
1992_8xdaily_atmos.nc
1993_8xdaily_atmos.nc
1990_daily_atmos.nc
1991_daily_atmos.nc
1992_daily_atmos.nc
1993_daily_atmos.nc
1990_month_atmos.nc
1991_month_atmos.nc
1992_month_atmos.nc
1993_month_atmos.nc

in my directory.

And what I need to do is to catch the file with 8xdaily in their names and do some commend per file.

Basically, I guess the code should be like

for file in (what I'm asking)
do (do some commend using $file)
done

Thanks!

Hi.

Basically, it would.

for file in *8xdaily*; do
  (do some commend using "$file")
done

But it might depend how many files there are.

1 Like