#!/bin/sh # since "perl -p ... -n ..." will be treated by perl as just # "perl -p ... ..." (not allowing the -n to override the -p) # we have to scan through any switches on the command line, # so that commands like "x12cat -ne 'print if /^PLB/' ..." # will work as expected... but still allow an implicit "-p" # if no "-n" is specified. Granted this isn't perfect... # But this isn't so bad, because an explicit "-p" can override # this. looptype="" for i do case "$i" in -m*) ;; # -m and -M start command-line "use" directives, -M*) ;; # "n"s in them should be ignored -*n*) looptype=n;; -h) echo 'x12cat: "magic" x12 spooler wrapper around command-line perl. -splits files by segment terminator -auto sets $f and $c to (regex-escaped) field and component separators -auto sets the autosplit to the field separator (for the -a autosplit) -allows -pe or -ne operations on file (or none at all to just cat the file)'; exit;; -*) ;; *) break;; esac done if [ "x$looptype" = "x" ]; then looptype=p fi perl -l -$looptype -e 'BEGIN{$SIG{PIPE}="exit"; $|=1; $/=\108; ($f,$c,$/)=(<> =~ /^ISA(.).{100}(.)(.?\r?\n?)/); ($f,$c)=("\Q$f","\Q$c"); se ek ARGV,0,0; $.=0}' -F'/$f/' "$@"