sffhdr

sffhdr              - to read from stdin
or  sffhdr filename         - to read from file filename
or  sffhdr -s "zczc" -e ".\n" filename
or  sffhdr -s "\001" -e "\002" -o newfile filename
or  cat rhubarb | cut 1-20 | sffhdr -o /world/ruby -
or  sffhdr -z pramfile filename

Simple program to read in a file, split off a defined header, read certain hdr
fields and output those and (optionally) the text.

Header strings start with a keyword up to a delimiter. eg:
    add_resource_fork=never
And are assumed to be on a single line (called line separator)

The program expects a file to be in the format of :
    (start of header string) - optional
    Header
    (end of header string)  - optional
    Text            - optional

It expects each line in the header to be in the format of :
    (keyword) (delimiter or separator) (optional parameter field) (end of line)
There can be leading spaces before the keyword which may or may not, be
ignored.
The delimitor is a single chr and is optional

If there are no input switches the input is piped in via stdin and output will
be just the text (ie strip the header)

The contents of the keywords are normally output in the order specified in the
parameter file or input switch line. (ie 1st specified or topmost in the
parameter file is output first then the next and so on). The order can also be
in that the data arrives using the -r input switch or 'dataorder:' keyword.

A parameter file in sfftables can be specified with the following :
    ; comment line
    keyword: Keywords to scan for in the input      default: none
        There can be up to 40 keywords specified.
    soh:    Start of header string used in the input    default: no soh
    eoh:    End   of header string used in the input    default: ~\n
    eoln:   End of line string used in the input        default: any CR NL combination
    outname: output file path and queue         default: stdout (ie to screen)
    fiphdr: File is Fip Style Header (including filename)   default: no
    delim:  Delimitor chr between keyword and parameter default: ':'
    outsep: The end-of-a-field chr              default: \n
        A single chr signifying the end of each header field
        (with any associative data)
    striptext: strip the text               default: output text
    keepspc: do NOT ignore leading spaces           default: strip them
        preceding a keyword
    casesens: Keywords are case sensitive           default: no they are not
        ie field : 'ARDVARK' is not the same as 'aardvark'
    textlen: length of text to display.         default: 0 meaning all text
        This is the maximum no of chrs of text to display.
    nltextlen: length of text to display.           default: 0 meaning all text
        This is the maximum no of chrs of text to display.
        Up to the end of the first non-blank line
    spctext: Convert any non-printing chr           default: leave text as is
        (including CR and NL) to SPC
    before-file:    Template file in FipSeq         default:none
        to be added before the 'befhdr', hdr and text
    after-file: Template file in FipSeq         default:none
        to be added after the text (and 'afttxt')
    befhdr: String to add at the top of output file.    default: none
    afthdr: String to add after the end of output file  default: none
    beftxt: String to add at the top of output file     default: none
    afttxt: String to add after the end of output file  default: none
    dataorder: Output fields in the order the data arrives. default: in parameter
file order
    keepoutspc: Preserve leading and trailing Spaces    default: delete
        from each output field and text.
    preserve-duplicates: If outputting to a file,       default: overwrite
        the default is to Overwrite any file with the same name.
        This flag forces a new file to be created.
    selector-client-file: Path/Filename for a Selector file default: none
        This also needs a selector header field
        The syntax of the file is :
            ; comment
            (key) # (bit offset 1) # (bit offset 2) # (name)
            bt#24#25#Bar Flys Visen

    selector-group-file: Path/Filename for a Selector file  default: none
        This also needs a selector header field
        The syntax of the file is :
            ; comment
            (group-key) # (selector codes) # (group-name)
            002#0001001111111111111111110010101....#Online

    selector-FipHdr-input: FipHdr field holding the     default: none
        destinations to select on.
        eg  selector-fiphdr-input:AE
        and AE holds    AE:dm+ag+we+zz
    selector-FipHdr-output: FipHdr field holding the    default: none
        resultant selector
        eg  selector-fiphdr-output:AZ

Input switches :
    filename    input filename is always last (if needed)
    If there is at least one switch, use '-' to signal input is from stdin.

    -z : parameter file         default: none

Either  -o : output file path and queue     default: stdout (ie to screen)
Or  -f : single field to output     default: none
        Syntax: -f add_resource_fork
        Remember to quote spaces and funny chrs
        There can be up to 40 '-f' - if vi can handle it !
Either  -h : File is Fip Style Header (including filename)  default: no
Or  -H : A FipHdr string            default: no
Or  -s : start-of-header string     default: none
    -e : end-of-header string       default: ~\n

    -l : line separator string      default: any CR NL combination
    -d : delimiter chr between keyword and parameter    default: ':'
    -D : output delimiter chr       default: \n
        A single chr separator between fields (and text)
        if more than one was specified.
    -X : strip the text         default: output text
    -Z : do NOT ignore leading spaces   default: strip them
        preceding a keyword
    -c : Keywords are case sensitive    default: no they are not
        ie field : 'ARDVARK' is not the same as 'aardvark'
    -t : length of text to display      default: 0 meaning all text
        This is the maximum no of chrs of text to display.
    -T : length of text to display      default: 0 meaning all text
        This is the maximum no of chrs of text to display.
        Up to the end of the first non-blank line
    -r : output in data order       default: parameter file order
    -R : add FipHdr field and output file   default: no
        with fiphdr and data as per input
    -v : version and exit
For those switches with parameters, the parameter MUST be separated by a space.

Note that if defining Unix escape chrs in scripts, you will probably need to
escape the escapes ! eg : \n becomes \\n 

Note you can preserve the output filename for the output when using '-o' by
specifying the FipHdr file ZN which is added at the end. (Remember the dbl \\),
    -o /fip/spool/2brouted/\\ZN

Example :
Incoming file
    afpsvr=EtherDibble
    atalkd =  "le0:99"
    xxx
    somerandomtextline which goes onandonandonandon ....

Program : cat Piddle | sffhdr -f afpsvr -e xxx -s "" -X -d"|"

Gives : 'EtherDibble|'

Other env varis can be used to define where the system is :
    SFF_HOME    where the home or top queue is.     default: /fip
            eg  setenv  SFF_HOME    /ripexpress/underware
    SFF_LOG     where the log files queue is        default: (SFF_HOME)/log
    SFF_SPOOL   where the data queues are       default: (SFF_HOME)/spool
    SFF_TMP     where the tmp data queues is        default: (SFF_HOME)/x
            THIS MUST BE ON THE SAME UNIX VOLUME as SFF_SPOOL queues.
            ie if spools are on /data99 which is hard disk /dev/sd0, you MUST also
            have the TMP queue on the same disk/partition

NOTE that for all BUT SFF_HOME, if the parameter starts with a '/' then it is a
hard, absolute path; if not then the spool area is under SFF_HOME.
    eg  setenv  SFF_SPOOL   /data7      will look under /data7 for queues
    while   setenv  SFF_SPOOL   data7       will look under /fip/data7

(copyright) 2024 and previous years FingerPost Ltd.