title: Executing nested loops+foreach+csh
body: <p>It's been a while since I used csh formatting and I am having a little bit of trouble with a few things. Things seem so much easier to execute in Matlab, however I need to do this on the terminal because of the programs I am trying to interact with.</p>
  <p>So here's what I want to do: I have a file del.txt that is structured like this</p>
  <p>1</p>
  <p>2</p>
  <p>3</p>
  <p>4</p>
  <p>etc. So each value is in it's own row and there's one column for all the data. I have a bunch of other files that are within my directory. I want to match up say value 1 (which in this case is 1) with file 1 and value 2 with file 2, etc and so on and so forth. So here's what I did...</p>
  <p>Code:</p>
  <h1>!/bin/csh</h1>
  <p>foreach a (<code>cat del.txt</code>)</p>
  <p>foreach sta(<code>ls *.HHZ</code>)</p>
  <pre><code>echo a is $a
  
  echo $sta
  
  
  cat &lt;&lt;END&gt;&gt;macro.m
  </code></pre>
  <p>r $a</p>
  <p>r $sta</p>
  <p>END</p>
  <pre><code>sac macro.m
  
  rm macro.m
  </code></pre>
  <p>end</p>
  <p>end</p>
  <p>However what I achieve is that it loops through all of the values in del.txt and each file and then moves on to the next file within my directory and loops through all of the values. I'm having trouble figuring out the format that this should be in to match up the correct values. I'm not doing much within the script yet until I can get them to match up. Please help Can someone tell me what I'm doing wrong? I read that the foreach command will execute all the commands on each file..but haven't been able to find a way to get around this. What I want it to do is take value 1 from del.txt and match it up with file 1 (sta) from the directory finish the loop, then take value 2 from del.txt and match it up with file 2 from the directory (sta). I've never done more than just simple iterations with csh on one subset of files, and I am not sure how to reference the values to one another. Any help would be greatly appreciated. I haven't found a simple way to do this without writing everything out. I looked at the 'for' and 'while' commands..if there is a simple way to do it I'm not seeing it.</p>
  <p>Cheers,
  K</p>