English 中文(简体)
修补假
原标题:Executing nested loops+foreach+csh

当时我使用了sh式布局,我对一些事情没有什么麻烦。 在Matlab执行的情况似乎非常容易,但是由于我试图与方案互动,我需要在终点站这样做。

So here s what I want to do: I have a file del.txt that is structured like this

页: 1

2 P-4月, 2 P-3月, 2 FS, 2 NS

3月

4月

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 P-4月, 2 P-3月, 2 FS, 2 NS with file 2 P-4月, 2 P-3月, 2 FS, 2 NS, etc and so on and so forth. So here s what I did...

法典:

!/bin/csh

(cat del.txt)

foreach sta(ls *.HHZ)

echo a is $a

echo $sta


cat <<页: 1>>macro.m

页: 1

r 主 费

页: 1

sac macro.m

rm macro.m

结束

结束

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 P-4月, 2 P-3月, 2 FS, 2 NS from del.txt and match it up with file 2 P-4月, 2 P-3月, 2 FS, 2 NS 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.

Cheers, K

问题回答

缩略语 我的理解是正确的,你有一份 t子文件,将列出扼杀物,你希望与档案相匹配。

我现在特别发言:

我要说的是价值1(在这种情况下是1)与档案1相对应。

你们想把1号卷宗与1号档案相匹配。

在此,根据这一假设,可以找到解决办法(这将有助于你走过路):

#Store value in file.txt in a array
set file_var = `cat file.txt`
#Store file list in my_dir in a var
set my_dir = <your dir path>
set file_list_var = `ls $my_dir`

#Let s print "file Match: for every match
foreach var1 ($file_var)
     foreach var2 ($file_list_var)
          if("$var1" == "$var2") echo $var1 = $var2 : Match Found.
     endif
endif




相关问题
Mysql Foreach Child show Max() and Min() in a single line

Is it possible to use a select statement so that it returns Max and min columns of a child row foreach Parent record? So foreach parent record that has MANY child records I want to see the Max and ...

Foreach in SQL?

I m not quite sure how to do this in SQL. Here it is in pseudocode: Take the list of nodes with content type X. For each node, take the value of field Y. Insert into term_nodes VALUES ((tid that ...

Custom container requirement to work with Qt s foreach

What is the bare minimum amount of code to create a custom container that would work with Qt foreach macro? I have this so far template< class T > class MyList { public: class iterator { ...

foreach loops & stdclass objects

I ve seen similar questions on here but I can t seem to apply the solutions to my problem. I have a variable called $results which I got from an API. I ll change the proper nouns so as to protect my ...

PHP - Foreach loops and ressources

I m using a foreach loop to process a large set of items, unfortunately it s using alot of memory. (probably because It s doing a copy of the array). Apparently there is a way to save some memory with ...

Hide a column programmatically in MS-Access

I want to hide or show a column based on variable data from a users selection. How do you set a column to hidden in MS-Access 2003? For Example, After user change event... For Each ctl In Me....

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have ...

Changing a struct inside another struct in a foreach loop

The following code prints (when invoking MyMethod): 0 0 0 1 I would expect it to print: 0 0 1 1 Why is this? Code: private struct MyStruct { public MyInnerStruct innerStruct; } private ...

热门标签