Find a phrase in a file
Find a phrase in a file
(OP)
All- So the last time I wrote a program in Fortran was over 15 years ago. I have Chapman's book and trying to refresh my memory now. It's coming back to me, but slowly (old age).
So my problem. I have a file that contains a lot of information in sections and need strip out each section to another file. The sections starts with *NAME and ends with a * or $. Below is an example:
*NODE
600204 2.8416665 -0.132341 0.6456926
600205 2.8416665 -0.1343255 0.6204348
600206 2.8416665 -0.13631 0.595177
600207 2.8416665 -0.1618106 0.595177
600208 2.8416665 -0.1873112 0.595177
600209 2.8416665 -0.2128118 0.595177
600210 2.8416665 -0.2383125 0.595177
600211 2.8416665 -0.2638131 0.595177
600212 2.8416665 -0.2893137 0.595177
600213 2.8416665 -0.3148143 0.595177
600214 2.8416665 -0.3403149 0.595177
...
...
* !or may end with $
The file has multiple *NODE sections in different places in the file. How do I search for *NODE in a file, take that information in between, and write it to another file?
Any suggestion will be very helpful....
Roger
So my problem. I have a file that contains a lot of information in sections and need strip out each section to another file. The sections starts with *NAME and ends with a * or $. Below is an example:
*NODE
600204 2.8416665 -0.132341 0.6456926
600205 2.8416665 -0.1343255 0.6204348
600206 2.8416665 -0.13631 0.595177
600207 2.8416665 -0.1618106 0.595177
600208 2.8416665 -0.1873112 0.595177
600209 2.8416665 -0.2128118 0.595177
600210 2.8416665 -0.2383125 0.595177
600211 2.8416665 -0.2638131 0.595177
600212 2.8416665 -0.2893137 0.595177
600213 2.8416665 -0.3148143 0.595177
600214 2.8416665 -0.3403149 0.595177
...
...
* !or may end with $
The file has multiple *NODE sections in different places in the file. How do I search for *NODE in a file, take that information in between, and write it to another file?
Any suggestion will be very helpful....
Roger





RE: Find a phrase in a file
RE: Find a phrase in a file
This is something that you can Macro Record in Word and wrap with a FOR loop. The following is an EXCEL macro that finds a word in a WORD file "transmittance" and copies the value from the text file back into the Excel file
CODE
'
' Lowtran7 macro to paste Lowtran transmission results into Excel Spreadsheet
' Macro recorded 1/23/98
'
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim ColIndex, RowIndex, StartRow, Done, Index
Dim FileName, SheetName
Dim WordApp As Object
Dim Trans As String
Set WordApp = GetObject(, "word.application")
FileName = ActiveWorkbook.Name
SheetName = ActiveSheet.Name
Sheets(SheetName).Select
Done = False
ColIndex = ActiveCell.Column
RowIndex = ActiveCell.Row
StartRow = RowIndex
Cells(RowIndex, ColIndex).Select
With WordApp.Selection.Find
.Text = "transmittance ="
.Replacement.Text = ""
End With
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
For Index = 1 To 25
WordApp.Selection.Find.ClearFormatting
WordApp.Selection.Find.Execute
WordApp.Selection.MoveRight unit:=wdCharacter, Count:=1
WordApp.Selection.MoveRight unit:=wdSentence, Count:=1, Extend:=wdExtend
' WordApp.Selection.Copy
Trans = WordApp.Selection.Text
WordApp.Selection.MoveDown unit:=wdLine
Cells(RowIndex, ColIndex).Select
' ActiveSheet.Paste
ActiveCell.Formula = Trans
RowIndex = RowIndex + 1
Next
Cells(StartRow, ColIndex).Select
End Sub
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
Chinese prisoner wins Nobel Peace Prize
RE: Find a phrase in a file
Thanks alot...
RE: Find a phrase in a file
CODE
Check if buff(1:1) is '*'. If it isn't, read (buff, ...) if you wish to read the data
If it is,
ll = len(trim(buff))
if (buff(ll:ll) .eq. '$') then do whatever.
RE: Find a phrase in a file