The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
foreach loop ROOZ Shell Programming and Scripting 3 06-05-2008 04:20 PM
using foreach loop sam4now Shell Programming and Scripting 6 04-26-2008 12:22 PM
Foreach loop haze21 Shell Programming and Scripting 4 11-16-2007 03:11 AM
foreach folder eltinator Shell Programming and Scripting 7 08-13-2007 03:37 AM
foreach command ?! geoquest UNIX for Dummies Questions & Answers 5 05-20-2002 06:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-27-2007
JimWork JimWork is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
foreach/grep help!

#!/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
  #2 (permalink)  
Old 07-27-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Jim,
Duplicate threads are not allowed here.

Please remove one of them:
http://www.unix.com/unix-for-dummies...grep-help.html
  #3 (permalink)  
Old 07-27-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Jim,
The syntax you are using is very similar to 'perl'.

The 'foreach' is a command from 'csh'.:

Code:
#!/bin/csh
foreach x (67402996 67402998)
 grep -a $x FINAL2006.dat >> MISSING_RECORDS.dat
end

  #4 (permalink)  
Old 07-27-2007
JimWork JimWork is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
Thanks!

I have a new problem: my Cygwin install doesn't appear to have csh.exe in bin... How do I get that?
  #5 (permalink)  
Old 07-27-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
See if you have 'ksh':

Code:
#!/bin/ksh
for x in 67402996 67402998
do
  echo 'x = '$x
done

  #6 (permalink)  
Old 07-27-2007
JimWork JimWork is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 3
#!/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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0