Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-13-2012
Registered User
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Executing nested loops+foreach

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.

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

Code:
1
2
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 with file 2, etc and so on and so forth. So here's what I did...


Code:
#!/bin/csh
foreach a (`cat del.txt`)
  foreach sta(`ls *.HHZ`)
    echo a is $a
    echo $sta


    cat <<END>>macro.m
r $a
r $sta
END
    sac macro.m
    rm macro.m

  end
end

I added the extra end and now 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?

Cheers,

K

Last edited by Scott; 04-13-2012 at 01:20 PM.. Reason: Code tags please
Sponsored Links
Closed Thread

Tags
csh, for loops, foreach, nested for loops

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Nested for loops jacksolm Shell Programming and Scripting 13 08-12-2011 10:37 AM
nested for loops taiL Shell Programming and Scripting 5 09-30-2009 11:02 PM
Nested foreach in perl nmattam Shell Programming and Scripting 2 09-28-2009 04:08 AM
Shell Integer with nested foreach bonesy Shell Programming and Scripting 0 04-29-2009 11:09 PM



All times are GMT -4. The time now is 10:44 AM.