gmdune 0 Newbie Poster

Hi All,

I have a list of txt files that I need to grep out for specific content and then create individual based on the txt file name. Here's my situation: I have been given a list of txt files, for example file is named cp205.txt, and I want to grep out all mentions of 'cp205' on all the text files in the directory. Here's some output that I have received from the command line:

$ ls
camb_ws.txt cp313_dir.txt incoming.txt output-set2 red
cp205_dir2.txt disk-output.txt milan-merlin.txt palermo-venice_ferrari_morgan_ninja.txt rho_aer.txt
cp205_dir.txt done non-red projects-old.txt test.txt
cp313_dir2.txt genoa.txt octal-incoming projects.txt verona.txt

$ grep -ir cp205 *
camb_ws.txt:cp205_dir2.txt
camb_ws.txt:cp205_dir.txt
camb_ws.txt:cp205.txt
cp205_dir2.txt: Directory of C:\Projects\cp205
cp205_dir2.txt:11/04/2005 09:34 PM 24,064 CP205 Task List.doc
cp205_dir2.txt: Directory of C:\Projects\cp205\debug
cp205_dir2.txt: Directory of C:\Projects\cp205\debug\new
cp205_dir2.txt: Directory of C:\Projects\cp205\globalmodel
cp205_dir2.txt: Directory of C:\Projects\cp205\globalmodel\new
cp205_dir2.txt: Directory of C:\Projects\cp205\globalmodel\temp
cp205_dir2.txt: Directory of C:\Projects\cp205\Inventories
cp205_dir2.txt: Directory of C:\Projects\cp205\New
cp205_dir2.txt: Directory of C:\Projects\cp205\New\Asiax2
cp205_dir2.txt: Directory of C:\Projects\cp205\reemis
cp205_dir2.txt: Directory of C:\Projects\cp205\SMOKE Files
cp205_dir.txt: Directory of C:\Projects\cp205
cp205_dir.txt:11/04/2005 09:34 PM 24,064 CP205 Task List.doc
cp205_dir.txt: Directory of C:\Projects\cp205\debug
cp205_dir.txt: Directory of C:\Projects\cp205\debug\new
cp205_dir.txt: Directory of C:\Projects\cp205\globalmodel
cp205_dir.txt: Directory of C:\Projects\cp205\globalmodel\new
cp205_dir.txt: Directory of C:\Projects\cp205\globalmodel\temp
cp205_dir.txt: Directory of C:\Projects\cp205\Inventories
cp205_dir.txt: Directory of C:\Projects\cp205\New
cp205_dir.txt: Directory of C:\Projects\cp205\New\Asiax2
cp205_dir.txt: Directory of C:\Projects\cp205\reemis
cp205_dir.txt: Directory of C:\Projects\cp205\SMOKE Files
genoa.txt:C:\Projects\cp205
milan-merlin.txt:C:\shuyun\projects\cp205
milan-merlin.txt:/usr2/shuyun/project/cp205

As you can see, there are different files that contain the word 'cp205'. The problem I'm having is putting this into a a foreach script (using tcsh) and have it output into another directory with a filename based on the name of the file. So it would be something like this:

$ grep -ir cp205 * > done/cp205-done.txt

What I've tried to do is put all the file names in the directory into one file, like 'camb.txt'. Here's my code:

foreach n ( `cat camb_ws.txt` )
foreach? grep -ir $n cp205 > $n.txt
foreach? end

When I run run this nothing happens...any help would be appreciate...Thx