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