# Solved: Findstr question



## ColleenR (Nov 16, 2009)

Hi,

I am trying to find files in a specific directory that contain the following line:

where the final double quotes contain a value in the format similar to "13 Nov 2009 10:18:46" (day, month, year, hour, minute, second).

I've tried using FINDSTR but I think I'm doing it wrong:

FINDSTR >H:\DisposalDatePages.txt /m /c:"\"ato_date_disposal\" content=\".*\"" *.htm

Any assistance is greatly appreciated.

Cheers
Colleen


----------



## ghostdog74 (Dec 7, 2005)

are you trying to get what is inside content="" ?? anyway, if you can download and use gawk for windows(see my sig) , 

```
C:\test>more file.txt
this is line
<meta name="ato_date_disposal" content="13 Nov 2009 10:18:46">
this is line

C:\test>gawk "BEGIN{FS=\"content=\042\"}/ato_date_disposal/{ gsub(/\042.*/,\"\",$2); print $2}" file
13 Nov 2009 10:18:46
```


----------



## ColleenR (Nov 16, 2009)

@ghostdog74

I am trying to get a list of files that contain a line that starts with *<meta name="ato_date_disposal"* with a value inside the *content=""*

Unfortunately, I can't download stuff to the work computer


----------



## ghostdog74 (Dec 7, 2005)

then you can use vbscript. findstr can't really "get" a value for you. it can only search for strings. assuming you are finding .txt files. change accordingly.

```
Set objFS=CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
	If objFS.GetExtensionName(strFile) = "txt" Then
		Set objFile = objFS.OpenTextFile(strFile)
		Do Until objFile.AtEndOfStream
			strLine = objFile.ReadLine
			If InStr(strLine,"ato_date_disposal") > 0 Then
				s = Split(strLine,"content=")
				s(1) = Replace(s(1),"""","")
				what_i_want = Mid(s(1),1,InStr(s(1),">")-1)
				WScript.Echo what_i_want & " found in "& strFile.Name				
			End If
		Loop			
		objFile.Close
	End If 		
Next
```
save the above as myscript.vbs and on command line

```
C:\test>more file.txt
this is line
<meta name="ato_date_disposal" content="13 Nov 2009 10:18:46">
this is line

C:\test>cscript /nologo myscript.vbs
13 Nov 2009 10:18:46 found in file.txt
```


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

You're on the right track ColleenR
Just need to use the */R* switch to tell *FindStr* to use the search string as a regular expression, and don't use */C:*, as that specifies a literal string, not a regular expression.
And I find it easier to put the redirection at the start of the line, rather than in the middle:

```
>H:\DisposalDatePages.txt Findstr /I /R /M "\"ato_date_disposal\" content=\"..*\"" *.htm
```
If you need to verify that what is in the quotes after content= is actually a date, the following will get close.
There's limits to the length of a search string with Findstr, so it won't let me verify the full time format, just up to the 1st character of the seconds.
This will find a string that contains the following string:
*"ato_date_disposal" content="dd MMM YYYY HH:MM:S*
followed by a single character, then a *">*
In other words it checks that the quotes after content contains a two digit date starting with 0-3, space, three letter month, space, 4 digit year starting with 1 or 2, space, a two digit hour starting with 0, 1, or 2, a colon, a two digit minute starting with 0-5, a colon, a number 0 through 5, and a single character
If there is no date in the content field it will not output the file name to the *DisposalDatePages.txt* file (i.e.,you have content="" or content="Some Text")
This requires the date and time fields to always be 2 digits

```
@Echo Off
>Search.txt Echo.\"ato_date_disposal\" content=\"[0-3][0-9].[ADFJMNOS][aceopu][bcglnprtvy].[1-2][0-9][0-9][0-9].[0-2][0-9]:[0-5][0-9]:[0-5].\"^>
>H:\DisposalDatePages.txt Findstr /I /R /M /G:search.txt *.htm
Del Search.txt
```
If you need to verify that the last digit is a number, or the date, hour, or minutes could be a single digit, or you need to include the *meta name=* part, you'd need to use VBScript with a Regular Expression. I can get to that later today if you really need it. I don't use it much so I'll have to look up just what is allowed in the RegEx pattern.

EDIT: Forgot to mention you also need to use *..** to check for characters inside the quotes, as *.** matches zero or more, so you need the first period to match a character.

HTH

Jerry


----------



## ColleenR (Nov 16, 2009)

@ghostdog74
Thank you for the help, but I am not a developer, so unfortunately, most of what you said went over my head. Sorry. I do appreciate the effort 

@TheOutcaste
Thank you. I don't need to verify what is inside the quotes, it is standard, trusted output from another system.

I found that when I ran the code from the first example, it returned all files that contained the meta tag, not just the ones with a value in content="".

So, I ran the second example and it worked perfectly. Thank you again.  

Cheers
ColleenR


----------

