If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > cshell questions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-11-02, 12:51
nicomen nicomen is offline
Registered User
 
Join Date: May 2002
Location: Ca
Posts: 2
cshell questions

I am *very* new to shell programming, so please be gentle.

I am trying to write a small script using a nested foreach loop. I have 4 files which contain a list of numbers, and one file that contains the bad numbers that are contained in the above-mentioned 4 files. I would like to be able to match up (from bad number file) the bad numbers listed in the 4 files, but I'm not sure how to make the one file search the other 4...?

I've looked in various sites and cannot seem to find anything that gives me a hint...so any help would be appreciated. Here's a rough of what I am trying to construct:

foreach i ( file1 file2 file3 file4 )
foreach j ( ~/badnum )

...and then I'm not sure...I'm thinking tho, that in my "foreach j" I may need to "cat badnum"?

Thanks in advance

nicomen
Reply With Quote
  #2 (permalink)  
Old 05-12-02, 12:39
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
You are on the right track:

something like the following:
foreach badnum (`cat badnumfile`)

next you can do a number of tests -- do a grep against the 4 files to test that particular bad number, redirect the output to a file and test to see if the file is non-zero in length -- you can use a foreach of the filenames to do this, so you would have nested foreach loops. You can cat the values out from the 4 files and use an if statement to do a comparison (this method would be more time consuming).

Good luck.
Reply With Quote
  #3 (permalink)  
Old 05-13-02, 14:18
nicomen nicomen is offline
Registered User
 
Join Date: May 2002
Location: Ca
Posts: 2
Thank you...I appreciate your response. Although I am no closer to completing the script than I was before, your comments supported my plan of attack.

nicomen
Reply With Quote
  #4 (permalink)  
Old 08-20-02, 04:34
WingMan WingMan is offline
Registered User
 
Join Date: Aug 2002
Location: UK
Posts: 87
Something like this ??

Code:
#!/bin/sh

integer check
badnum=`cat badnumfile`

for File in ( file1 file2 file3 file4 ) ; do
 check=`grep -i ${badnum} ${File}

 if [ ${check} -eq 0 ] ; then
    echo "Bad nums found in file " ${File}
 fi

done
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On