Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANN: 'AWK global variables space' and 'Stamp format' libraries

30 views
Skip to first unread message

cj2ke

unread,
Aug 13, 2016, 12:21:40 AM8/13/16
to
AWK Scripts pages:
https://sites.google.com/site/cj2kxiv/home/awk-scripts

'AWK global variables space' library page:
https://sites.google.com/site/cj2kxiv/home/awk-scripts/agvs-awk

And test script page for agvs.awk:
https://sites.google.com/site/cj2kxiv/home/awk-scripts/test_agvs-awk

'Stamp format' library page:
https://sites.google.com/site/cj2kxiv/home/awk-scripts/stampf-awk


############################################################
# agvs.awk: AWK global variables space

# Allow opperation with a differents global variables space (agvs).
# Space is defined as a colection of global variables.
# The space is saved in AGVS array with a stamp as reference for the collection.
# When saving a space, the function return a stamp for later use in program.

# usage:
# stamp=agvs() push agvs return: new stamp
# agvs(stamp) pop agvs return: 0 or 6 for restored and deleted
# agvs(stamp, "+") save, return: stamp
# agvs(stamp, "?") test, return: 0 or 1 for saved
# agvs(stamp, "%") restore, return: 0 or 2 for restored
# agvs(stamp, "-") delete, return: 0 or 4 for deleted
# agvs(stamp, "!") pop, return: 0 or 6 for restored and deleted

# arguments:
# stamp: string that group global variables in AGVS array
# default to hex random integer as string

# op: operations on a spcifics gvs;
# default: if stamp=="" push else pop

# operations alias:
# /in|test|saved|[?]/ test if a space is saved in AGVS array
# /save|add|push|[+]/ add a space to AGVS array
# /load|restore|[%]/ restore a space from AGVS array
# /del|delete|[-]/ delete a space from AGVS array
# /pop|[!]/ restore and delete a space from AGVS array

# sel: argument to select spcifics global variables
# first char is the splitter; "|SUBSEP|FS|RS| ... |NF|$0"
# default to;

############################################################
test_agvs.awk

Use next line to test agvs.awk

logs=`awk -v filelog="%P_%T-_%s_%n.log" -f stampf.awk`;\
echo $logs >$logs ;\
awk -f agvs.awk -f test_agvs.awk >>$logs

############################################################
stampf.awk

The stampf.awk library provide 2 functions you can use in your awk programs:

stampf(format)
This function return a string construct from format.
Format usage (look in source code for exemples):

%n NanoSec
%s SinceEpochSec
%(p|P) ProcID|Program name
%(r|R) (single shot|Repeating) random
%% %
%c processor number
%(g|G) group
%(u|U) user
%Tc tree pid path and c=character use as separator

############################################################
proc_info(rinfo, ARRAY, command)

This function is use whit stampf() and can have any uses. 

Arguments:
rinfo: return info item from ARRAY, using one in the next list
(command,comm,psr,user,uid,group,gid,sess,ppid,pid,output,ps_info,ps)

ARRAY: contain process info items from command

command: from which process info are collected

For shell usage:

logs=`awk -v filelog="%P_%T-_%s_%n.log" -f stampf.awk`

For testing:

awk -v test_proc_info=1 -v test_stampf=1 -v filelog="%P_%T-_%s_%n.log" -f stampf.awk
awk -v test_stampf=1    -v filelog="%P_%T-_%s_%n.log" -f stampf.awk
awk -v test_proc_info=1 -v filelog="%P_%T-_%s_%n.log" -f stampf.awk



--
Regards,
Jacques

cj2kxvm dot nospam at gmail dot com
0 new messages