Searching for Strings

July 18, 2009 at 10:11:17
Specs: Windows XP, Core Duo/1GB
Hi Friends,

I am kinda new to Batch file programming.
I have few text files in a folder. (eg: mp3_1.txt mp3_2.txt mp3_3.txt etc etc). All these text files contains some mp3 songs file names in each line.

I want to search a specific string in all these files and I want to display the matching lines as

<tab> line1
<tab> line32
<tab> line45

<tab> line2
<tab> line6

I dont want other files in the folder to be displayed. (only the file contaning the string should be displayed)
Can anyone guide me in this regard?

See More: Searching for Strings

Report •

July 18, 2009 at 13:42:11
I think you are doing it backwards. The mp3 text files entries should be all added to a database. Then indexed by title, artist, location, etc. acccording by how you want it accessed.

Report •

July 18, 2009 at 19:07:14
thanks for the quick reply.
i think that will solve a big problem. bt if i want to have these files seperate, is there any solution?

Report •

July 18, 2009 at 20:53:59
You still can have the text files separate. The database will contain the information that you consider important or a link back to the text file.

Report •

Related Solutions

July 18, 2009 at 21:49:50
Another method is to use a utility like GREP. It will do the seach almost exactly as you require except for the tab.
grep options string *.txt

Report •

July 18, 2009 at 23:29:45

Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
strSearch = "test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
	strFileName =strFile.Name
	strFilePath = strFile.Path
	strFileExt = objFS.GetExtensionName(strFile)
	If strFileExt = "txt" Then
		Set objFile = objFS.OpenTextFile(strFile)	
		Do Until objFile.AtEndOfLine
			strLine = objFile.ReadLine
			If InStr(strLine,strSearch) > 0 Then
				s = s & strLine & "-> line: " & linenum
			End If 
		If f=1 Then
			WScript.Echo strFileName 
			WScript.Echo vbTab & s
		End If 
	End If 

save as myscript.vbs and on command line

c:\test> cscript /nologo myscript.vbs

GNU win32 packages | Gawk

Report •

July 19, 2009 at 19:10:35
wow.. thank you for the code. it worked with me. I have also tried to do it using bat file. Well, i came up with a solution today.
I am putting the code here.

set/p cho=Please Enter Keyword:
cd "CD Content"
echo Search Results for - %cho%
for %%f in (*.*) do (
findstr /i "%cho%" "%%f" > found.cdtxt
for %%t in (found.cdtxt) do (
if %%~zt GTR 0 (
echo %%f
for /F "tokens=* delims=" %%t in (found.cdtxt) do (
echo %%t
del found.cdtxt
cd ..

thank you guys for helping me with the code.

Report •

Ask Question