DosTips.com

A Forum all about DOS Batch
It is currently 04 May 2016 00:01

All times are UTC-06:00




Post new topic  Reply to topic  [ 23 posts ]  Go to page 1 2 Next
Author Message
PostPosted: 19 Apr 2012 14:21 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
Hello, can you help me with script to find all .txt files which contain more than one occurrence of "</coordinates>" ? To get a list of files.


Top
   
PostPosted: 19 Apr 2012 14:34 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5567
This searches *.txt and in subdirectories and if "</coordinates>" is found on two or more separate lines then it will log the filename in found.txt


Code:
@echo off
for /f "delims=" %%a in ('dir *.txt /b /s') do (
for /f "delims=" %%b in ('find "</coordinates>" ^<"%%a" ^|find /c /v "" ') do (
if %%b GTR 1 >>"found.txt" echo %%a
)
)


Top
   
PostPosted: 20 Apr 2012 02:46 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
Thank you.

PS:
But it is very slow.


Top
   
PostPosted: 20 Apr 2012 03:12 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
Your command takes too long. Maybe the command could to be faster if I would use grep. But here I fail.

Code:
@echo off
for /f "delims=" %%a in ('dir *.kml /b /s') do (
 for /f "delims=" %%b in ('grep "</coordinates>" <"%%a"') do (
   echo %%b 
  pause
 )
)
pause


Top
   
PostPosted: 20 Apr 2012 03:18 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5567
doscode wrote:
Thank you.

PS:
But it is very slow.


You're welcome.

But I dare say it is a shitload faster than you opening each file in a text viewer, searching for text, closing it and repeating with the next 200 files. :)


Top
   
PostPosted: 20 Apr 2012 03:26 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
I run web server on my computer and I have application that can load that files one by one, searches for text, and replaces every file. Directory structure is complicated, and there is cca 10-50 or 80 files in every folder. It takes 15 seconds to complete all edit actions by server. So it is damn fast. But when I run your command nothing happens. I waited few minutes and still not completed. So I think, here is something wrong. I thought it should be simple to find that strings and count them. And sure on server I would do it in 10 seconds. But because I want to use this script to recover files which are damaged (contain twice occurence of the word) I want to copy files from the location which is out of the server document folder. Therefor would like to use CMD if it can be fast. In other way, I can copy the backup to the server document directory and then make command for web app.


Top
   
PostPosted: 20 Apr 2012 03:39 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5567
doscode wrote:
I run web server on my computer.
Directory structure is complicated, and there is cca 10-50 or 80 files in every folder.
It takes 15 seconds to complete all edit actions by server. So it is damn fast. But when I run your command nothing happens. I waited few minutes and still not completed. So I think, here is something wrong.


I can't tell what you are doing. Are you running it in the root directory? How many .txt files are involved? What size are the files, on average?

Quote:
I thought it should be simple to find that strings and count them. And sure on server I would do it in 10 seconds.


Well it is simple - my script is only 6 lines or so.


Top
   
PostPosted: 20 Apr 2012 03:43 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
Statistics:
3822 files, 321 folders.
5,63MB total
14,9MB total on disk

2kB per file

Edit:
Actually it takes cca 4 minutes to find first file. But there is much more files to find.


Top
   
PostPosted: 20 Apr 2012 04:11 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5567
doscode wrote:
Statistics:
3822 files, 321 folders.
5,63MB total
14,9MB total on disk

2kB per file

Edit:
Actually it takes cca 4 minutes to find first file. But there is much more files to find.


The first task for CMD is to gather a list of every file in the tree, and isolate the .txt files.

EDIT: Are you sure you aren't running it from the root directory?

If you put the batch file and find.exe on a ramdisk then it may work faster, although disk caches are in place and should help anyway.
Actually, why not copy it all to a ramdisk and run it from there. It will run faster, if that is important to you.


Top
   
PostPosted: 20 Apr 2012 04:21 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
I never worked with ramdisk and idk how to use them.

I implemented a restore function into my web app. It will restore file automatically, if there is an error. Only weakness is the need to copy all folder structure including files into document server location.


Top
   
PostPosted: 20 Apr 2012 05:56 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3038
doscode wrote:
Statistics:
3822 files, 321 folders.
5,63MB total
14,9MB total on disk

2kB per file

Edit:
Actually it takes cca 4 minutes to find first file. But there is much more files to find.

Those statistics look a little skewed.


Top
   
PostPosted: 20 Apr 2012 06:40 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
why


Top
   
PostPosted: 20 Apr 2012 06:43 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3038
doscode wrote:
why

Commas are usually used as a thousand separator.
So it that suppose to be 5.63MB or did you drop a zero at the end and it is suppose to be 5,630MB?
14.9MB or 14,900MB?


Top
   
PostPosted: 20 Apr 2012 07:25 
Offline

Joined: 15 Feb 2012 14:02
Posts: 163
I just have rewrite what I had seen on dialog window of my local system. The size of whole structure has 14,9MB on disk. 15MB.


Top
   
PostPosted: 20 Apr 2012 08:14 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
u can use notepad++ it has a search feature that search in many files and replace words u caould try if batch didn't help


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 23 posts ]  Go to page 1 2 Next

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited