Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

find word in all files uder one directory

Posted on 2008-06-10
6
Medium Priority
?
1,573 Views
Last Modified: 2013-12-27
experts,

i have a question. i have a directory under that there are 1000 files. now i need to find one word out of 1000 files. i am not sure in which file the word is present. now i need to find all the files which contain word.

if the the directory contain sub dierctories it need to check that all the directories and sub directories
0
Comment
Question by:pavan27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 21755845
find . -type f | xargs grep WhateverWord
0
 
LVL 1

Expert Comment

by:imxco
ID: 21755849
This isn't exactly what you are looking for but maybe a point in the right direction.  The is a vbs script that does what you want on a windows system.  You might be able to take the logic and change it to your system.
'****Searches C:\UTSFiles for a given screen # and displays matches
'****
'*******************************************************************
 
										'****Set conts & variables
Const ForReading = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
GlobalCounter = 0
strComputer = "."
strSAWNum = inputbox("What word do you want to find? ")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
										'****Set search folder
Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\UTSFiles'} Where " _
        & "ResultClass = CIM_DataFile")
If strSAWNum <> "" Then 							'****Only search if a value is entered.
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"   
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 400 
objExplorer.Left = 0
objExplorer.Top = 0
 
Do While (objExplorer.Busy)
    Wscript.Sleep 200
Loop    
 
objExplorer.Visible = 1             
objExplorer.Document.Body.InnerHTML = "<center>Retrieving information. " _
    & "This might take several minutes to complete.  Please do not close this window, it will close automatically when finished.</center>"
Set colServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2"). _
    ExecQuery("Select * from Win32_Service")
For Each objService in colServices
    Wscript.Sleep 200
Next
 
	For Each objFile In colFileList
    	strName = objFile.FileName 
    	FoundCounter = 0
    	Set objFile = objFSO.OpenTextFile(objFile.Name, ForReading)		'****Open input file
		Do Until objFile.AtEndOfStream  				'****read thru the file line by line until end of file
    			strNextLine = objFile.Readline
			If InStr(strNextLine, strSAWNum) <> 0 Then
				If FoundCounter = 0 Then 			'**********Only Display Results if it hasn't been displayed yet
					Wscript.Echo "Found " & strSAWNum & " in " & strName & "." '*****Show the file name
					FoundCounter = FoundCounter+1		'Counter up
					GlobalCounter = GlobalCounter+1		'Counter up
				End If
    			End If
		Loop
   	 objFile.Close 'close input file
	Next 'file
objExplorer.Quit
End If
Wscript.echo "Found " & GlobalCounter & " file(s) matching " & strSAWNum & "."	'****Show results

Open in new window

0
 
LVL 1

Author Comment

by:pavan27
ID: 21755960
Great  reply.

suppose i have 100 file. now i don't want to search all 1000 files for a specific word. can i use filter condition on list of files. suppose i need to check only 100 file out of 1000 for specific word.

how do i do that
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 58

Accepted Solution

by:
amit_g earned 2000 total points
ID: 21756148
The command would depend on what that criteria is.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21756940
What type of filter do you want to use?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 21760956
the command find give you different options for searching files, you may see

man find

to see these options
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question