Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


search multiple text files for elevations

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3107
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> search multiple text files for elevations
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 search multiple text files for elevations - 5/24/2005 3:52:51 PM   
  bevan

 

Posts: 3
Score: 0
Joined: 5/24/2005
From:
Status: offline
Hello all,

Here is my problem:
I have a number of text files (approx 150), which contain 'Eastings', 'Northings' and 'Elevations' (space delimited).These are the DEM files and are are quite large (13MB each)
The format is:
1858180 5663500 1314.49
1858180 5663520 1317.05
1858180 5663540 1321.05
1858180 5663560 1326.28
1834180 5703920 527.07
1834180 5703940 522.08
1834180 5703960 518.69
1834180 5703980 517.73
1834180 5704000 516.66

I have a 'site' file which contains that i want to find elevations for. e.g sites.txt
1834180 5703960
1858180 5663520

I would like search all the DEM files and output a results file with the results (fnnily enough) e.g results.txt
1834180 5703960 518.69
1858180 5663520 1317.05

Any help would be appreciated
 
 
Post #: 1
 
 Re: search multiple text files for elevations - 5/25/2005 12:34:54 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
So, if I am understanding you right, you have your DEM files which contain, in space delimited format, 3 entries, (Eastings, Northings, Elevations). Then you have your "site" file which will contain what? Eastings and Northings? If that is in fact what they are, what you want to is compare what you have in your site file to what is in a particular DEM, if it matches write that line to a results file.

i.e.

DEM contains
123 456 78.9
987 654 32.1

Site contains
123 456

Results will contain
123 456 78.9

is this what you are looking for?

(in reply to bevan)
 
 
Post #: 2
 
 Re: search multiple text files for elevations - 5/25/2005 8:17:16 AM   
  bevan

 

Posts: 3
Score: 0
Joined: 5/24/2005
From:
Status: offline
Mike,

Yes that is correct, any ideas?

I have been trying to use regular expressions and so far can return the string i have been searching for but not the elevation associated with it.

(in reply to bevan)
 
 
Post #: 3
 
 Re: search multiple text files for elevations - 5/31/2005 2:57:11 PM   
  bevan

 

Posts: 3
Score: 0
Joined: 5/24/2005
From:
Status: offline
This is what i came up with:
not pretty but seems to work...


Option Explicit
Dim objFSO, objSearchFile, objOutputFile, objLogFile, objDataFile, strComputer, objWMIService,

FileList
Dim strText, arrSites, tempFile, output, temp, strSite, objFile

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSearchFile = objFSO.OpenTextFile _
("c:\Bevan\Combining_Tool\rainfall_sites.txt", ForReading)
'("c:\Bevan\Combining_Tool\test.txt", ForReading)

Set objOutputFile = objFSO.CreateTextFile("output.txt")
Set objLogFile = objFSO.CreateTextFile("log.txt")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF

{Win32_Directory.Name='C:\Bevan\Combining_Tool\RENAMED_XYZ_tab_delimited_files'} Where " _
& "ResultClass = CIM_DataFile")
'creates a list of all files in folder

'("ASSOCIATORS OF {Win32_Directory.Name='C:\Bevan\Combining_Tool\testgrds'} Where " _
' & "ResultClass = CIM_DataFile")


strText = objSearchFile.ReadAll 'reads all of search file (sites to find) into a string
objSearchFile.Close

arrSites = Split(strText, vbCrLf) 'splits the string based on vbCrLf creates an array
'arrSites contains all the sites for which elevations are needed

For Each objFile In FileList
Set objDataFile = objFSO.OpenTextFile(objFile.Name, ForReading)
'Wscript.Echo objFile.Name & " File name"
objLogFile.Writeline objFile.Name

Do Until objDataFile.AtEndOfStream
temp = objDataFile.ReadLine

For Each strSite in arrSites

If UCase(Left(temp,15)) = strSite Then
objOutputFile.Writeline temp
End If
Next
Loop

objDataFile.Close

Next


Wscript.Echo "Finish

(in reply to bevan)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> search multiple text files for elevations Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts