Sponsored Content
Top Forums Shell Programming and Scripting awk printf for user defined variables Post 302138527 by jabberwocky on Tuesday 2nd of October 2007 07:38:12 AM
Old 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

pre defined variables

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

Return an array of strings from user defined function in awk

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

using AWK printf with userdefine variables

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

Crontab jobs don't see variables defined in /etc/profile

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

User defined functions in awk

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

[solved] awk: placement of user-defined functions

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

Question about awk - create a user-defined variable

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

Doing math using user defined input and system environment variables

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

How are environment variables defined in a Gnome terminal session?

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

Call user defined function from awk

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
MAXDB_CHANGE_USER(3)							 1						      MAXDB_CHANGE_USER(3)

maxdb_change_user - Changes the user of the specified database connection

       Procedural style

SYNOPSIS
bool maxdb_change_user (resource $link, string $user, string $password, string $database) DESCRIPTION
Object oriented style bool maxdb::change_user (string $user, string $password, string $database) maxdb_change_user(3) is used to change the user of the specified database connection as given by the $link parameter and to set the current database to that specified by the $database parameter. In order to successfully change users a valid $username and $password parameters must be provided and that user must have sufficient per- missions to access the desired database. If for any reason authorization fails, the current user authentication will remain. Note Using this command will always cause the current database connection to behave as if was a completely new database connection, regardless of if the operation was completed successfully. This reset includes performing a rollback on any active transactions, closing all temporary tables, and unlocking all locked tables. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Object oriented style <?php /* connect database test */ $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } if ($result = $maxdb->query("SELECT * FROM dual")) { $row = $result->fetch_row(); printf("Result: %s ", $row[0]); $result->free(); } /* reset all and select a new database */ if (!$maxdb->change_user("DBADMIN", "SECRET", "DEMODB")) { printf("Database not running "); } else { printf("Database running "); } /* close connection */ $maxdb->close(); ?> Example #2 Procedural style <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (!$link) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } if ($result = maxdb_query($link, "SELECT * FROM dual")) { $row = maxdb_fetch_row($result); printf("Result: %s ", $row[0]); maxdb_free_result($result); } /* reset all and select a new database */ if (!maxdb_change_user($link, "DBADMIN", "SECRET", "DEMODB")) { printf("Database not running "); } else { printf("Database running "); } /* close connection */ maxdb_close($link); ?> The above example will output something similar to: Result: a Database running SEE ALSO
maxdb_connect(3), maxdb_select_db(3). PHP Documentation Group MAXDB_CHANGE_USER(3)
All times are GMT -4. The time now is 07:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy