- 论坛徽章:
- 0
|
以下一段awk代码是用来分析dxf格式的文件的,
dxf文件格式大概是这样:
...
TEXT
8
2
10
747.16
20
273.75
40
10.00
1
#-25
0
TEXT
8
2
10
748.23
20
272.15
40
10.00
1
#-26
0
LINE
8
8
10
750.09
20
279.58
11
751.65
21
277.70
0
TEXT
8
2
10
750.09
20
279.58
40
10.00
1
#-27
0
TEXT
8
2
10
751.65
20
277.70
40
10.00
1
#-28
0
LINE
8
8
10
750.09
20
273.09
11
752.93
21
274.79
0
TEXT
8
2
10
750.09
20
273.09
..........
使用方式$andxf.awk filenam.dxf ,功能是抽取一些必要的信息出来,但是我看来看去也看不明白,谁能给我简单注解一下?"#"后面是我的问题,
- awk '
- BEGIN {
- TXT_no=-1 #这里TXT_no的值是-1
- Str=""
- }
- {
- if( TXT_no != -1 )
- ++TXT_no #这里TXT_no的值是多少?
- if( $0 == "TEXT" )
- TXT_no=0
- if( TXT_no == 2) #这里能到达吗?
- S2=$0
- if( TXT_no == 18){
- S18=$0
- if( S2 == 19){
- # the second line below the line with "TEXT" is a
- # flage, if the value is "19", means this section
- # is used for the text in paper patten.
- # if the value is "1", there is another meaning.
- gsub( " *\^\^* *\~\~*", "^ ", S18)
- gsub( " *\~\~* *\^\^*", "~ ", S18)
- gsub( " *\^ *", "^ ", S18)
- gsub( " *\~ *", "~ ", S18)
- Str=sprintf("%s:%s", Str, S18)
- }
- else{
- split(S18, s, ":")
- if ( s[1] == "Annotation" ){
- PC=s[2]
- printf ("%s%s\n", PC, Str)
- TXT_no=-1
- Str=""
- }
- }
- }
- }
- ' $1
复制代码 |
|