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 > Search text in all files in directory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-14-05, 20:53
omnSweetness omnSweetness is offline
Registered User
 
Join Date: Jan 2005
Posts: 6
Search text in all files in directory

I am attempting to search all files in the current for searchText. Then display the filename, line number, and entire line.

What I am thinking of doing is:

grep il "searchText" > tempFile

then look through the temp file and extract each file name, and use another grep or maybe an awk statement to display the filename, line number, and entire line.

I am sure this is a round-about way of doing things. I am attempting this in a Bourne shell so if anyone can help me thank you.

-Sweetness
Reply With Quote
  #2 (permalink)  
Old 01-18-05, 02:57
srsjc srsjc is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
grep -rn "search pattern" * > outfile

r- recursive
n- line number

Out put will be like this
FileName: lineNumber: line
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