File: sortglos.awk

package info (click to toggle)
gawk 1%3A5.2.1-2
  • links: PTS
  • area: main
  • in suites: bookworm, trixie
  • size: 25,256 kB
  • sloc: ansic: 54,687; awk: 14,521; yacc: 6,814; sh: 6,418; makefile: 3,004; sed: 119; python: 31; csh: 6
file content (51 lines) | stat: -rw-r--r-- 964 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
BEGIN {
	pr="y";
	npre=0;
	po="n";
	npos=0;
	}

pr=="y"      { npre++; pre[npre]=$0; }
$1=="@table" && $2=="@asis" { pr="n";nite++; next; }

po=="y"      { npos++; pos[npos]=$0; }
$1=="@end" && $2=="table"   {
	po="y";
	npos++;
	pos[npos]=$0;
	# last item...
	vec[nite]=nlin;
}

	{ nite++; }

END {
	for ( i=1; i<=npre; i++ ) { print pre[i]; }
	if ( srt=="y" ) {
		n=asorti(entr,ital);
		##print "n=",n;
		for ( i=1; i<=n; i++ ) {
			#printf("=========> %3.3d %s\n",i,ital[i]);
			# ital[i] is the sorted key;
			j=entr[ital[i]];
			# j is the original item number
			for ( k=1; k<=vec[j]; k++ ) {
				print dat[j,k];
			}
		}
	}
	if ( srt=="n" ) {
		for ( i=1; i<=nite; i++ ) {
			printf("=========> %3.3d %2.2d %s\n",i,vec[i],titl[i]);
			for ( j=1; j<=vec[i]; j++ ) {
				print dat[i,j];
			}
		}
		print "========================= END";
	}
	for ( i=1; i<=npos; i++ ) { print pos[i]; }
	print "@c npre=" npre;
	print "@c nite=" nite;
	print "@c npos=" npos;
}