Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: matching co...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 26 Topic 2199 of 2241
Post > Topic >>

Re: matching column variables from two awks!

by Ed Morton <morton@[EMAIL PROTECTED] > Mar 21, 2008 at 12:04 AM

On 3/20/2008 11:36 PM, spacegoose wrote:
> i have a program that prints out a formatted df command
> by sorting and grepping and using awk to print it out.
> 
> it basically executes df -h | grep whatever | sort -n +5 and then
> awks
> to a nice printout like:
> 
> disk size capacity
> ------------------
> foo	20gb	70%
> moo	40gb	25%
> bar	20gb	70%
> 
> i'd like to add a new column "accounts" to this print out.
> 
> the no. of accounts is derived from a command:
> awk {'print $5'} myFile |sort |uniq -c |sort -nr
> 
> which prints rows like:
> 
> 450 	foo
> 300	moo
> 104	bar
> 
> i want to integrate this command into the formatted df program's
> output.
> i can't figure out how to appropriately append the "account count"
> column from the myFile command, to the appropriate row of the
> formatted df output,
> e.g. where col 1 from the formatted df output matches col 2 of the
> myFile command.
> 
> so it looks like this:
> 
> 
> disk size capacity accounts
> ---------------------------
> foo	20gb	70%	450
> moo	40gb	25%	300
> bar	20gb	70%	104
> 
> 
> Thanks for any hints!
> sg

$ cat file1
450     foo
300     moo
104     bar

$ cat file2
disk size capacity
------------------
foo     20gb    70%
moo     40gb    25%
bar     20gb    70%

$ awk '
NR==FNR{acct[$2]=$1;next} FNR==1{sfx=" account"} FNR==2{sfx="--------"}
FNR>2{sfx=" "acct[$1]} {print $0 sfx}' file1 file2
disk size capacity account
--------------------------
foo     20gb    70% 450
moo     40gb    25% 300
bar     20gb    70% 104

but I expect there's a much simpler way to get your desired output using
awk on
your raw output rather than doing all that post-processing with other
tools
first. If you provide your "df -h" output and "myFile" contents that got
you the
data above, we could probably help.

	Ed.




 26 Posts in Topic:
matching column variables from two awks!
spacegoose <spacegoose  2008-03-20 21:36:28 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-21 00:04:37 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 07:15:57 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-21 09:40:47 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 09:33:56 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-21 14:59:28 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 13:51:43 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-21 16:16:40 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 14:00:13 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 15:03:17 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 16:09:17 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-21 18:32:47 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-21 22:00:21 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-22 07:37:33 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-22 07:37:12 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-22 18:16:25 
Re: matching column variables from two awks!
gazelle@[EMAIL PROTECTED]  2008-03-22 23:23:43 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-22 19:44:09 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-22 22:13:30 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-23 00:41:29 
Re: matching column variables from two awks!
"Rajan" <svr  2008-03-23 17:04:58 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-23 16:50:45 
Re: matching column variables from two awks!
gazelle@[EMAIL PROTECTED]  2008-03-23 22:19:40 
Re: matching column variables from two awks!
"Rajan" <svr  2008-03-23 20:58:50 
Re: matching column variables from two awks!
spacegoose <spacegoose  2008-03-24 08:55:09 
Re: matching column variables from two awks!
Ed Morton <morton@[EMA  2008-03-26 08:13:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 4:01:34 CDT 2008.