Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern on one line but data on another

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I’m an intermittent user of awk, and need some help with a program.

I need to pull node numbers and spatial coordinates out of a data file that is not formatted in a way to make it at all convenient. (sample data inserted below, with the data I need annotated – those comments don’t appear in the real data file. The data is organized into blocks – there are various types of blocks with their own formats, but the one I’m interested in is shown.) That leaves me with the problem of matching a pattern on one line and reading data that appears on a different line in the file. [ I’ve seen several other questions like this in the archives of this forum, but I couldn’t make any of their solutions work in my case.]


16
71
4
72
4
0
VERTEX
5
57 < node numbers (in hexadecimal)
100
AcDbEntity
8
flange mesh
100
AcDbVertex
100
AcDbPolygonMeshVertex
10
8.768275930423 < x coordinate
20
0.978177227092 < y coordinate
30
0.0 <z coordinate
70
64
0
VERTEX
5
58
100
AcDbEntity
8
flange mesh
100


I’m uncertain how to attack this. I could create a set of conditions to match, but would I use the next command with it?:

/VERTEX/ {next / 5/ {node = $1} , etc.

or could I redefine the Record Separator and proceed as if each data block were one long line.


ADDED LEVEL OF DIFFICULTY: I’m working with GAWK 3.1 in an MSDOS window under Windows 98. There seem to be undocumented syntax changes compared to the manual and my experience on Unix platforms. I’m having trouble seeing if my programs fail because of hidden problems like that or my lousy programming. Any hints on living with Windows would be welcome, too.

Thanks in advance. I'll be reading &quot;Effective AWK Programming&quot; until I get a reply here.

Keith
 
This may do what you want. It assumes that each section always has the same number of lines between the lines of interest.

/VERTEX/ {
getline;getline;node = $1
for (i=0;i<10;i++) getline
x = $1
getline; getline; y = $1
getline; getline; z = $1
print node &quot; &quot; x &quot; &quot; y &quot; &quot; z
}

I ran it using gawk without any problems. Put it in a file, v.awk say, and run it using

gawk -f v.awk infile > outfile CaKiwi
 
That worked great, thanks very much. I guess I need to learn more about getline -- it never occured to me to use it.

The syntax problems I mentioned didn't come up. The main thing that I've noticed is that single quotes ( ' ) are &quot;unrecognized&quot;.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top