The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How printf handles empty variables Skyybugg Shell Programming and Scripting 2 04-24-2008 01:32 PM
need help with User Defined Function user_prady Shell Programming and Scripting 11 11-18-2007 08:51 PM
User defined service markdrury UNIX for Dummies Questions & Answers 1 02-09-2006 01:08 AM
pre defined variables sumsin High Level Programming 7 11-30-2005 12:13 PM
User defined signal 1 nitesh_raj AIX 0 01-29-2005 02:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2007
jabberwocky jabberwocky is offline
Registered User
  
 

Join Date: Jan 2006
Location: uk
Posts: 17
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
  #2 (permalink)  
Old 10-02-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,418
One way:
Code:
find / -type d -name $Database -exec du -sk {} \; 2>/dev/null |
awk -v Db=$Database '{
sum += $1
}
END {
printf("%10s\t%20s\n",Db,sum) }'
Jean-Pierre.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0