#!/bin/awk -f BEGIN { # A record is an IE heading RS = "-- =+\n-- IE: [A-Z][A-Za-z0-9-]+" # A field is a line FS = "\n" # Usage explanation if (ARGC != "2") { print "Usage: " ARGV[0] " file.asn" print "Splits file.asn generated by txt2asn into one file per module" exit } file_prefix = ARGV[1] gsub(/.asn$/, "", file_prefix) outfile = "" heading = "" } { # Search for the start of a module definition in every field (= line) of the IE for (i = 1; i <= NF; i++) { if ($i ~ /[[A-Z][A-Za-z0-9-]+ DEFINITIONS AUTOMATIC TAGS ::=/) { split($i, module_name, " ") outfile = file_prefix "-" module_name[1] ".asn" } } # See below about heading if (outfile != "") { print heading $0 > outfile } # RT is the record terminator i.e., the string that matched RS # It actually is the heading of the next record, so store it # to be printed with the next record. heading = RT }