The UNIX and Linux Forums  

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


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 02:03 PM
find then grep flame_eagle Shell Programming and Scripting 7 03-13-2008 07:19 AM
find , grep james94538 UNIX for Dummies Questions & Answers 2 02-01-2008 01:34 PM
find and grep sarwan High Level Programming 4 04-10-2006 04:05 AM
find & grep Anika UNIX for Dummies Questions & Answers 11 02-01-2001 08:19 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 3
grep and find

Hey, I have a question about using grep and find together to locate all C programs in a directory containing certain words and open the vi editor with each file. I'm not sure how to do this in one command (as in one line). I know find has a "-exec" option that can call vi, but how do you combine this with grep to find only those containing the words "int main ("? Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-07-2008
Registered User
 

Join Date: Apr 2008
Posts: 1
This should work:

find ~ *.c -exec vi `grep -l "int\ *main\ *("` {} \;

find finds all files *.c and executes vi provided that grep finds the string "int main(". The -l in grep returns the filename.

Merely out of curiosity:

1) Is this 11.19.ii in "Your Unix The Ultimate Guide" by Das?
2) Are you in Sean's class at UCD?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0