As it was ultimately Don Craguns idea that saved the whole project i can as well give something back to the community. This is my stanza file parser, which was written only using ksh without any external programs.
The stanza structure
There is some inconsistency as to what exactly is meant by "stanza". I use it in the sense IBM uses it, i.e. in the file /etc/filesystems. It codes tabular data in the following form:
String values can be quoted to enclose white space like this:
and i added the capability for inline- as well as line-comments which work the same way as in the shell: everything after an (unquoted and unescaped) comment sign ("#") up to the end of line is a comment. Notice that escaping needs to be done by double backslashes:
The Parser
The parser is done in a shell function which is callable. The function gets the following parameters:
1) the input file to parse
2) the name of a handler function. This function is called with every successfully parsed stanza and is passed three parameters: the table name and the name of two arrays, one contains the column names and one the respective values. Both arrays are 1-based.
3) An (optional) flag (0 or 1) to switch on or off "double-checking". Consider the following stanza where "item2" ismentioned two times:
This flag determines wether such a condition is considered to be wrong (an error is raised and the stanza is rejected) or not.
4) The name of an array which contains table/columnname combinations along with "data types", separated by colons (":"). If such an array is passed the mentioned table/columnn-combinations are checked for the value being of the correct data type. Notice that i use "data type" rather losely here. Right now allowed types are:
"file" - name of an existing file
"int" - an integer
"num" any numeric (float, only decimal notation)
"char" - any string
I plan to add more "data types" (i.e. a valid file name of a non-existing file) in a later revision, if you have ideas: just tell me. Here is a sample array definition and the subsequent call to the parser function:
The Handler Function
The function name passed to the parser must point to a valid function in your script. The function named there will be called with every successfully parsed stanza entry. Here is a template for how the function could look like:
Compatibility Issues
I have tested the parser only with ksh93 but it should work with ksh88 too as i see no reason why it shouldn't. Test it thoroughly before depending on it, though. For the whole to work in bash, though, some work is perhaps needed. There are some function used in there which come from my library. The names should make it pretty obvious what their purpose is. If there is interest in this i can provide the rest of my library.
The Code
Here is a sample script that shows how to use the function. The handler function only prints the name of the table and the items and their values. It should give an idea about how to use the whole construct, though:
Here is a sample input file that shows what is possible:
I did my best to test the code above. Still, test for yourself before you use it in a critical setting. If you find bugs: PLEASE TELL ME! I'll be glad to weed them out.
bakunin
Last edited by bakunin; 01-08-2019 at 04:47 AM..
Reason: typo
These 5 Users Gave Thanks to bakunin For This Post:
DFT using pure ksh ONLY!
Well ksh now has its own DFT without the aid of AWK. The SINE, COSINE and SQRT functions are in the code directly and NOT sourced.
This is stand alone and requires nothing but ksh itself. Who would have even thought that this was possible until very recently?
Thanks to... (0 Replies)
I've one EDI file which is to be parsed into 7 different file.
I managed to extract required segments for a file(HEADER) to a separate file(sample3.dat) and is given below.
$ cat sample3.dat
REF*EI*273543997~
REF*2U*HELLO~
REF*G2*77685|132~
CLM*1000*0.00***12>B>1*N*A*Y*I~
CN1*05~... (5 Replies)
The default: stanza in /etc/security/limits is still set to 2097151 on fsize (max file size). I know tar had issues with large files but is there any other reasons for it? I'm thinking yes since it's still set to that by IBM.
Cheers,
DH (4 Replies)
Hi
need help parsing a file.
I have tag fields and values in a file with delimiter |.
sample records from the file listed below
8=value|9=value|35=value|49=value|56=value|34=value|50=value|48=value|10=value
8=value|9=value|35=value|49=value|56=value|34=value|51=value|48=value|10=value... (2 Replies)
Hi
I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email.
For example
-------
Script ABC
-------
a.ksh
b.ksh
c.ksh
I need to call all three scripts execute them and... (2 Replies)
ok, im going to start off by saying i am a newbee so some of the stuff i say may not be right.
but anyways, right now i am using ubuntu hardy for my main distrobution. i love it and all, but the main reason i switched to linux (besides drm and the blue screen i see on my comp about ten times a... (13 Replies)
Hi Friends,
I have a file as below :
machine1:
abc
xyz
qwerty
machine2:
jkl
mno
machine3:
hhh
kkk
qwerty
Now ...i need to find all the stanza names that have the pattern "qwerty'"
in it...( i need to get the output as machine1 and machine3 since... (4 Replies)
Hi guys, I do know how tu use linux (actully slack), i do know that linux was made from unix. Where can i get the unix? is that possible? Does it have any driver?
Help me plz! (2 Replies)