Hi, I was debating if I should put this in the dummies or scripts section, I apologize in advance if I chose poorly.
Fairly new to Unix and BASH scripting but I thought I made it fairly well given my limited understanding. However, the output indicates that it's looping and I'm ending up with a stupid large number of files.
If you fine folks here could help me puzzle out a more efficient code, I would greatly appreciate it.
for dir in `ls -d1 /raid/r04/wconnor/Sites/*_30km`; do
#Find the list of directories my files are in, there are several
for res in modqkm mod375m modhkm mod750m mod1km; do
#This is important to the ./spatbsq program
for file in `ls -S1 $dir | grep -v .hdr`; do
#Each directory contains a list of files, [file] and [file].hdr. this is to just grab all the non-.hdr files
./spatbsq -DS -F-9999 -B1000x6x1000 hyp2${res}.par ${dir}/${file} ${dir}/${file}.${res}
cp ${dir}/${file}.hdr ${dir}/${file}.${res}.hdr
done
#runs the spatbsq on the list above and then spits out the same filename with the ${res} on the end for both [file] and [file].hdr
done
done
He's the output from a folder with only one [file] and associated hdr. I don't know how to get the forum to make a scroll window so sorry for the long post. I've sorted it by date to try and help me understand what the script is doing. I'm pretty sure the problem arises because of the "for file in `ls -S1 $dir | grep -v .hdr`" but I'm at a loss of how I could rewrite this so it would only read it once. I've had no luck trying to set it as a variable but that may just be because I don't know how to do it properly. Perhaps outputting the ls command to a file then doing a cat as the argument in the for loop?
total 375940
-rw-rw-r-- 1 wconnor proj 852 Dec 5 13:44 lndsr_L71116034_03420090406_GDK_30km.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 5 13:44 lndsr_L71116034_03420090406_GDK_30km
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:19 lndsr_L71116034_03420090406_GDK_30km.modqkm
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:19 lndsr_L71116034_03420090406_GDK_30km.modqkm.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:20 lndsr_L71116034_03420090406_GDK_30km.mod375m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:20 lndsr_L71116034_03420090406_GDK_30km.mod375m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:21 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:21 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:22 lndsr_L71116034_03420090406_GDK_30km.modhkm
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:22 lndsr_L71116034_03420090406_GDK_30km.modhkm.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:24 lndsr_L71116034_03420090406_GDK_30km.mod375m.modhkm
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:24 lndsr_L71116034_03420090406_GDK_30km.mod375m.modhkm.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:25 lndsr_L71116034_03420090406_GDK_30km.modqkm.modhkm
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:25 lndsr_L71116034_03420090406_GDK_30km.modqkm.modhkm.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:26 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.modhkm
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:26 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.modhkm.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:30 lndsr_L71116034_03420090406_GDK_30km.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:30 lndsr_L71116034_03420090406_GDK_30km.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:32 lndsr_L71116034_03420090406_GDK_30km.mod375m.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:32 lndsr_L71116034_03420090406_GDK_30km.mod375m.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:34 lndsr_L71116034_03420090406_GDK_30km.mod375m.modhkm.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:34 lndsr_L71116034_03420090406_GDK_30km.mod375m.modhkm.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:36 lndsr_L71116034_03420090406_GDK_30km.modhkm.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:36 lndsr_L71116034_03420090406_GDK_30km.modhkm.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:39 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:39 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:41 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:41 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:43 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.modhkm.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:43 lndsr_L71116034_03420090406_GDK_30km.modqkm.mod375m.modhkm.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:44 lndsr_L71116034_03420090406_GDK_30km.modqkm.modhkm.mod750m
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:44 lndsr_L71116034_03420090406_GDK_30km.modqkm.modhkm.mod750m.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:51 lndsr_L71116034_03420090406_GDK_30km.mod1km
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:51 lndsr_L71116034_03420090406_GDK_30km.mod1km.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:56 lndsr_L71116034_03420090406_GDK_30km.mod375m.mod1km
-rw-rw-r-- 1 wconnor proj 852 Dec 6 17:56 lndsr_L71116034_03420090406_GDK_30km.mod375m.mod1km.hdr
-rw-rw-r-- 1 wconnor proj 12000000 Dec 6 17:59 lndsr_L71116034_03420090406_GDK_30km.mod375m.mod750m.mod1km
.. It goes on further but you get the idea