10-02-2007
awk printf for user defined variables
I am working on a SunFire 480 - uname -a gives:
SunOS bsmdb02 5.9 Generic_112233-08 sun4u sparc SUNW,Sun-Fire-480R
I am tyring to sum up the total size of all the directories for each running database using awk:
#!/usr/bin/ksh
for Database in `ps -efl | grep "ora_pmon" | grep -v grep | awk '{printf("%s\n"
,$NF)}' | cut -f3 -d'_' | sort`
do
export Database
# echo "$Database\c"
find / -type d -name $Database -exec du -sk {} \; 2>/dev/null |
awk '{
sum += $1
}
END {
printf("%10s\t%20s\n",$Database,sum) }'
done
#EOF
I can get output in the format Database NNNNNNNN using the echo command, now commented out. If I try to use printf in the awk statement to format the output for both Database name and sum, the printf statement does not pick up the value of $Database (or Database for that matter). If I use the echo command for the Database name, the output format is difficult to control. How can I get the database name recognised in the printf statement?
Thanks,
Jabberwocky
10 More Discussions You Might Find Interesting
1. Programming
Hi
First I want to explain the scenerio :
In my project I want to control the printing of some messages. Thats why I use
#ifdef MESSAGE
------------print message--------------
#endif
And when I compile the program with -DMESSAGE option, it shows all message and without -DMESSAGE option... (7 Replies)
Discussion started by: sumsin
7 Replies
2. Shell Programming and Scripting
Hello Friends,
Is it possible to return an array from a user defined function in awk ?
example:
gawk '
BEGIN{}
{
catch_line = my_function(i)
print catch_line
print catch_line
print catch_line
}
function my_function(i)
{
print "echo"
line= "awk"
line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies
3. Shell Programming and Scripting
seems simple but i've not been successfull in adding the value of a Variable to a every line of a file using AWK & printf
i've come up with the following, but it's not working.:mad:
--- mydatafile.dat
e.g. of data in file:
cau_actvty_fa_lrf.ksh
fan_soco_fa.ksh
ny_sum_lst.ksh... (4 Replies)
Discussion started by: danmauer
4 Replies
4. Shell Programming and Scripting
Is it true that Crontab jobs don't see variables defined in /etc/profile?
How to get around that? (4 Replies)
Discussion started by: proactiveaditya
4 Replies
5. Shell Programming and Scripting
Hi;
Is der ne to to use user defined functions for the values in awk
find $1 -type f -ls | nawk '{{print "|"$3"|"$5"|"$6"|"$8"|"$9"|"$10"|"} for(i=11;i<=NF;i++){printf("%s",$i)}}'
In above command i want to append some values returned by user functions on line.
thnks;
ajay (1 Reply)
Discussion started by: ajaypadvi
1 Replies
6. Shell Programming and Scripting
Hi folks,
is there any recommendation, especially from a point of performance, about where to place a user-defined function in awk, like in BEGIN{} or if it is only need once at the end in END{}? Or doesn't it matter at all since, awk is so clever and only interprets it once, wherever it is... (3 Replies)
Discussion started by: zaxxon
3 Replies
7. Shell Programming and Scripting
Hi, guys,
The content of file is below (from <UNIX® Shells by Example Fourth Edition>):
My code is below:
gawk -F'' ' { OFS = "****"; $3 = "(904)"; $8 = $5 + $6 + $7; print } ' lab3.data
The result is below:
So, where is the $1? Why is the variable $8 located at the wired position? (3 Replies)
Discussion started by: franksunnn
3 Replies
8. Shell Programming and Scripting
Hi,
I need some help to setup some environmental variables.
for example...Get A -> userdefined/user input
B -> a number.
c -> system variable...for example $GETCONF PAGE_SIZE
E = do some math using bc
display a message "The value is E"
setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies
9. UNIX for Beginners Questions & Answers
Hello... and thanks in advance for any help anyone can offer me with my question! I'm hoping someone will have a little patience with me and walk me through this!
I'm trying to understand a user login process on Centos 7 and I've gotten a bit confused trying to figure out when/how a Gnome... (4 Replies)
Discussion started by: bodisha
4 Replies
10. UNIX for Beginners Questions & Answers
My requirement is to call function ("fun1") from awk, and print its returned value along with $0.
fun1()
{
t=$1
printf "%02d\n", $t % 60;
}
echo "Hi There 23" | awk '{print $0; system(fun1 $3)}'
Any suggestions what to be modified in above code to achieve requirement.. (5 Replies)
Discussion started by: JSKOBS
5 Replies
LEARN ABOUT DEBIAN
ttk::spinbox
ttk::spinbox(3tk) Tk Themed Widget ttk::spinbox(3tk)
__________________________________________________________________________________________________________________________________________________
NAME
ttk::spinbox - Selecting text field widget
SYNOPSIS
ttk::spinbox pathName ?options?
_________________________________________________________________
DESCRIPTION
A ttk::spinbox widget is a ttk::entry widget with built-in up and down buttons that are used to either modify a numeric value or to select
among a set of values. The widget implements all the features of the ttk::entry widget including support of the -textvariable option to
link the value displayed by the widget to a Tcl variable.
STANDARD OPTIONS
-class -cursor -style
-takefocus -xscrollcommand
See the ttk_widget manual entry for details on the standard options.
STANDARD OPTIONS
-validate -validatecommand
See the ttk_entry manual entry for details on the standard options.
WIDGET-SPECIFIC OPTIONS
Command-Line Name:-from
Database Name: from
Database Class: From
A floating-point value specifying the lowest value for the spinbox. This is used in conjunction with -to and -increment to set a
numerical range.
Command-Line Name:-to
Database Name: to
Database Class: To
A floating-point value specifying the highest permissible value for the widget. See also -from and -increment. range.
Command-Line Name:-increment
Database Name: increment
Database Class: Increment
A floating-point value specifying the change in value to be applied each time one of the widget spin buttons is pressed. The up but-
ton applies a positive increment, the down button applies a negative increment.
Command-Line Name:-values
Database Name: values
Database Class: Values
This must be a Tcl list of values. If this option is set then this will override any range set using the -from, -to and -increment
options. The widget will instead use the values specified beginning with the first value.
Command-Line Name:-wrap
Database Name: wrap
Database Class: Wrap
Must be a proper boolean value. If on, the spinbox will wrap around the values of data in the widget.
Command-Line Name:-format
Database Name: format
Database Class: Format
Specifies an alternate format to use when setting the string value when using the -from and -to range. This must be a format speci-
fier of the form %<pad>.<pad>f, as it will format a floating-point number.
Command-Line Name:-command
Database Name: command
Database Class: Command
Specifies a Tcl command to be invoked whenever a spinbutton is invoked.
INDICES
See the ttk::entry manual for information about indexing characters.
VALIDATION
See the ttk::entry manual for information about using the -validate and -validatecommand options.
WIDGET COMMAND
The following subcommands are possible for spinbox widgets in addition to the commands described for the ttk::entry widget:
pathName current index
pathName get
Returns the spinbox's current value.
pathName set value
Set the spinbox string to value. If a -format option has been configured then this format will be applied. If formatting fails or is
not set or the -values option has been used then the value is set directly.
SEE ALSO
ttk::widget(3tk), ttk::entry(3tk), spinbox(3tk)
KEYWORDS
entry, spinbox, widget, text field
Tk 8.5.9 ttk::spinbox(3tk)