Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: Findstr question

Reply  
Thread Tools
ColleenR's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
15-Nov-2009, 10:21 PM #1
Solved: Findstr question
Hi,

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

<meta name="ato_date_disposal" content="">

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's Avatar
Member with 146 posts.
 
Join Date: Dec 2005
15-Nov-2009, 10:39 PM #2
are you trying to get what is inside content="" ?? anyway, if you can download and use gawk for windows(see my sig) ,
Code:
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's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
15-Nov-2009, 11:07 PM #3
@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's Avatar
Member with 146 posts.
 
Join Date: Dec 2005
15-Nov-2009, 11:57 PM #4
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.
Code:
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
Code:
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's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
16-Nov-2009, 08:33 AM #5
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:
Code:
>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
Code:
@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
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions


Last edited by TheOutcaste; 16-Nov-2009 at 08:40 AM..
ColleenR's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
16-Nov-2009, 07:42 PM #6
@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
Reply

Tags
findstr

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:29 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.