We aren't supposed to name executables 'test', because test already exists.goingnuts wrote:Cant get it running (named the script "test"):
~
Yes - a single applet (pmmon) and one with place for 5 (pmmon5).linktechnosaurus wrote:... didn't you already do one using only xlib and xpm though?
I will remember that - in this case I do not think that was the problem though...Bruce B wrote:We aren't supposed to name executables 'test', because test already exists.
I'll have to take a look and see if I can adapt my sit arg parsing logic to it so that it can be unlimited ... which reminds me, I found some nicer fonts in aicon to add to my txt2xpmgoingnuts wrote:Yes - a single applet (pmmon) and one with place for 5 (pmmon5).linktechnosaurus wrote:... didn't you already do one using only xlib and xpm though?
...
Code: Select all
#!/bin/awk -f
#FILENAME (name of current file) $FILENAME (contents of current file)
#NF number of fields, $NF last field
#NR line number in all files #FNR line number in current file
#ORS (default is "\n") #RS (default is "\n")
#OFS (default is " ") #FS (default is [ \t]*)
#system(command) run a command #close(filename) close(command)
#ARGC, ARGV similar to C, but skips some stuff
#IGNORECASE (default is 0) set to non-0 or use toupper() or tolower()
#ENVIRON array of env vars ex. ENVIRON["SHELL"] (equivalent of $SHELL)
#getline var < file ... close file or command | getline var
#index(haystack, needle) find needle in haystack
#length(string)
#match(string, regexp) returns where the regex starts, or 0
#RLENGTH length of /match/ substring or -1
#RSTART position where the /match/ substring starts, or 0
#split(string, array, fieldsep) split string into an array separated by fieldsep
#printf(format, expression1,...) print format-ted replacing %* with expressions
#%{c,d/i,e,f,g,o,s,x,X,%} char, decimal int, exp notation, float, shortest of
# exp/float, octal, string, hex int, capitalized hex int, a '%' character
#sprintf(format, expression1,...) store printf in a variable
#sub(regexp, replacement, target) replace first regex with replacement in target
#gsub(regexp, replacement, target) like gsub but for all regex in target
#substr(string, start, length)get substring of string from start to start+length
#print > /dev/stdin, /dev/stdout, /dev/stderr, /dev/fd/# or filename
#output can be piped like print $0 | command
#comparisons <,>,<=,>=,==,!=,~,!~,in use && for AND, || for OR, ! for NOT
# (~ is for regexp and "in" looks for subscript in array)
#/word/{...} like if match(...) {...} equivalent of grep
#(condition) ? if-true-exp : if-false-exp or use if (condition){}
#math +,-,*,/,%,**,log(x),exp(x),,sqrt(x),cos(x),sin(x),atan2(y,x),
#rand(),srand(x),time(),ctime()
#
#function name (parameter-list) {
# body-of-function
#}
BEGIN {
#actions that happen before any files are read in
}
#
{
#actions to do on files
}
#
END {
#actions to do after all files are done
}
Code: Select all
#useage: status [Options]
#Options
#Name:State:Tgid:Pid:PPid:TracerPid:Uid:Gid:FDSize:Groups:VmPeak
#VmSize:VmLck:VmPin:VmHWM:VmRSS:VmData:VmStk:VmExe
#VmLib:VmPTE:VmSwap:Threads:SigQ:SigPnd:ShdPnd:SigBlk:SigIgn
#SigCgt:CapInh:CapPrm:CapEff:CapBnd:Seccomp:Cpus_allowed
#Cpus_allowed_list:voluntary_ctxt_switches:nonvoluntary_ctxt_switches
status(){
echo $@ | awk 'BEGIN{FN=0}
FNR==1{FN++}
FN==1{
argc=NF
for(j=0;j<NF;j++){
argv[j]=$(j+1)
field[FN][$(j+1)]=$(j+1)
}
}
FN>1{
title=substr($1,0,length($1)-1)
$1=""
field[FN][title]=$0
}
END{
for(i=1;i<FN;i++){
for(j=0;j<argc;j++){
printf "%-20s\t", field[i][argv[j]]
}
printf "\n"
}
}
' - /proc/*/status
}
Code: Select all
awk 'BEGIN{RS="\0"}{print}' /proc/1/environ
technosaurus,technosaurus wrote:here is an example of how to give awk sane and useable "arguments" (see the argc and argv portions... note that "-" is stdin, so the arguments are read first followed by the rest of the files)
The rest of the example demonstrates how to store a 2 dimensional associative (named) array and iteratively print it after all files are processedand here is a bonus to get the init cmdline ... in case you were running in pfix=ram or somethingCode: Select all
#useage: status [Options] #Options #Name:State:Tgid:Pid:PPid:TracerPid:Uid:Gid:FDSize:Groups:VmPeak #VmSize:VmLck:VmPin:VmHWM:VmRSS:VmData:VmStk:VmExe #VmLib:VmPTE:VmSwap:Threads:SigQ:SigPnd:ShdPnd:SigBlk:SigIgn #SigCgt:CapInh:CapPrm:CapEff:CapBnd:Seccomp:Cpus_allowed #Cpus_allowed_list:voluntary_ctxt_switches:nonvoluntary_ctxt_switches status(){ echo $@ | awk 'BEGIN{FN=0} FNR==1{FN++} FN==1{ argc=NF for(j=0;j<NF;j++){ argv[j]=$(j+1) field[FN][$(j+1)]=$(j+1) } } FN>1{ title=substr($1,0,length($1)-1) $1="" field[FN][title]=$0 } END{ for(i=1;i<FN;i++){ for(j=0;j<argc;j++){ printf "%-20s\t", field[i][argv[j]] } printf "\n" } } ' - /proc/*/status }
Code: Select all
awk 'BEGIN{RS="\0"}{print}' /proc/1/environ
Code: Select all
status Name
awk: cmd. line:7: field[FN][$(j+1)]=$(j+1)
awk: cmd. line:7: ^ syntax error
awk: cmd. line:7: field[FN][$(j+1)]=$(j+1)
awk: cmd. line:7: ^ syntax error
awk: cmd. line:13: field[FN][title]=$0
awk: cmd. line:13: ^ syntax error
awk: cmd. line:18: printf "%-20s\t", field[i][argv[j]]
awk: cmd. line:18: ^ syntax error
awk: cmd. line:18: printf "%-20s\t", field[i][argv[j]]
awk: cmd. line:18: ^ syntax error
I used the awk included in Precise, I still haven't tested it with busybox awk, maybe it doesn't support 2-dimensional arrays? ... I guess It doesn't even need "field", that was just a random choice so the 2nd dimension can be the array name instead (so there would be an array named for each "Option") ... and as a bonus it would simplify the script.seaside wrote:This looks really handy.. However, this is what I get -Any ideas on what might be off?Code: Select all
status Name awk: cmd. line:7: field[FN][$(j+1)]=$(j+1) awk: cmd. line:7: ^ syntax error awk: cmd. line:7: field[FN][$(j+1)]=$(j+1) awk: cmd. line:7: ^ syntax error awk: cmd. line:13: field[FN][title]=$0 awk: cmd. line:13: ^ syntax error awk: cmd. line:18: printf "%-20s\t", field[i][argv[j]] awk: cmd. line:18: ^ syntax error awk: cmd. line:18: printf "%-20s\t", field[i][argv[j]] awk: cmd. line:18: ^ syntax error
Regards,
s