You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.3 KiB
Awk
82 lines
1.3 KiB
Awk
4 years ago
|
BEGIN {
|
||
|
level = 0;
|
||
|
printf( "{\"networks\":[" );
|
||
|
}
|
||
|
|
||
|
/^$/ {
|
||
|
nl = 1;
|
||
|
}
|
||
|
|
||
|
/^\tnetwork/ && level == 3 {
|
||
|
printf( "}" );
|
||
|
level = 2;
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\tnetwork/ && level == 2 {
|
||
|
printf( "]" );
|
||
|
level = 1;
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\tnetwork/ && level == 1 && nl == 1 {
|
||
|
printf( "},{" );
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\tnetwork/ && level == 0 {
|
||
|
printf( "{" );
|
||
|
level = 1;
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^$/ && level == 1 {
|
||
|
printf( "\"stations\":[" );
|
||
|
level = 2;
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\t\tstation/ && level == 3 && nl == 1 {
|
||
|
printf( "},{" );
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\t\tstation/ && level == 2 {
|
||
|
printf( "{" );
|
||
|
level = 3;
|
||
|
first = 1;
|
||
|
}
|
||
|
|
||
|
/^\tnetwork/ {
|
||
|
gsub(/network->/, "", $1);
|
||
|
printf( "\"%s\":\"%s\",", $1, $3 );
|
||
|
first = 0;
|
||
|
}
|
||
|
|
||
|
/^\t\tstation/ {
|
||
|
gsub(/station->/, "", $1);
|
||
|
printf( "%s\"%s\":\"%s\"", first ? "" : ",", $1, $3 );
|
||
|
first = 0;
|
||
|
}
|
||
|
|
||
|
/^..*$/ && nl == 1 {
|
||
|
nl = 0;
|
||
|
}
|
||
|
|
||
|
END {
|
||
|
if( level == 3 ) {
|
||
|
printf( "}" );
|
||
|
level = 2;
|
||
|
};
|
||
|
if( level == 2 ) {
|
||
|
printf( "]" );
|
||
|
level = 1;
|
||
|
};
|
||
|
if( level == 1 ) {
|
||
|
printf( "}" );
|
||
|
level = 0;
|
||
|
};
|
||
|
printf( "]}\n" );
|
||
|
}
|
||
|
|