#!/bin/bash
foreach x (67402996 67402998)
{
grep -a x FINAL2006.dat >> MISSING_RECORDS.dat
}
I'm trying to pass a list to the variable x, and then grep for that string in FINAL2006.dat...
Final2006.dat is in the same folder as my .sh file. I call this with a .cmd file...
At any rate, it doesn't seem to be working. Any thoughts?
Thanks!
jim
Jim,
The syntax you are using is very similar to 'perl'.
The 'foreach' is a command from 'csh'.:
#!/bin/csh
foreach x (67402996 67402998)
grep -a $x FINAL2006.dat >> MISSING_RECORDS.dat
end
Thanks!
I have a new problem: my Cygwin install doesn't appear to have csh.exe in bin... How do I get that?
See if you have 'ksh':
#!/bin/ksh
for x in 67402996 67402998
do
echo 'x = '$x
done
#!/bin/tcsh
foreach x (67402996 67402998)
grep -a $x FINAL2006.dat >> MISSING_RECORDS.dat
end
This *almost* works, but it only processes the first number (correctly! Woot!) and then stops.
Any thoughts?
jim
Your looping is working properly, try the following:
#!/bin/tcsh
foreach x (67402996 67402998)
echo 'x = '$x
end
Then your problem must be in the 'grep' statement.