Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: matching column variables from two awks!
xxx@x3$ df -h | grep dsk | sort +5

/dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/xp20
/dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/xp21
/dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/xp22
/dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/xp23
/dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/xp24
/dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/xp25
/dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/xp26
/dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/xp27


xxx@x3$ df
/local/ds/xp26(/dev/md/ds/dsk/x26):148445868 blocks 22517420 files
/local/ds/xp12(/dev/md/ds/dsk/x12):144276990 blocks 22608345 files
/local/ds/xp30(/dev/md/ds/dsk/x30):133775594 blocks 22412624 files
/local/ds/xp6 (/dev/md/ds/dsk/x6):121057960 blocks 22383983 files
/local/ds/xp4 (/dev/md/ds/dsk/x4):129103034 blocks 22193600 files



my program foo:

df -h | grep dsk | sort +5 | awk '

BEGIN {
printf("%-30s%12s%12s%12s%10s\n\n", "File System", "bytes", "used",
"available", "capacity")
printf("--------------------------------------------------------------------
----------
\n")
}

{
printf("%-30s%12s%12s%12s%10s\n", $6, $2, $3, $4, $5)
}


END {
}'


xxx@x3$ ./foo

File System                          bytes        used   available
capacity

----------------------------------------------------------------------------
--
/global/ds/xp0                    200G        139G         59G
71%
/global/ds/xp1                    200G        131G         67G
66%
/global/ds/xp10                   200G        129G         69G
66%
/global/ds/xp11                   200G        133G         65G
68%
/global/ds/xp12                   200G        131G         67G
67%
/global/ds/xp13                   200G        139G         59G
71%
/global/ds/xp14                   200G        139G         59G
71%
/global/ds/xp15                   200G        132G         66G
67%
/global/ds/xp16                   200G        138G         60G
70%
/global/ds/xp17                   200G        128G         70G
65%
/global/ds/xp18                   200G        133G         65G
68%



sample of myFile:

11     621 2008/03/21 12:44 xp4            256000 user/foo/INBOX
806   41722 2008/03/21 13:26 xp47           256000 user/bar/INBOX
2391  115428 2008/03/21 13:26 xp5            256000 user/moo/INBOX
2452  122771 2008/03/21 12:38 xp6            256000 user/123/INBOX
638   65484 2008/03/21 12:56 xp6            256000 user/345/INBOX
139    4892 2008/03/21 12:44 xp7            256000 user/789/INBOX
398   13403 2008/03/19 14:05 xp7            256000 user/1234/INBOX
392   32448 2008/03/21 14:14 xp8            256000 user/5678/INBOX

of which this:

xxx@x3$ awk {'print $5'}  myFile | sort |uniq -c | sort -n

shows:

1407 xp45
1496 xp40
1503 xp51
1524 xp49
1537 xp50
1539 xp42


where col 1 is the no. of accts. per "xp" partition.


my desired output will show col 1 (as above) on the appropriate row
(e.g. where partition matches, e.g. where col 2 above matches the end
of col 1 from my prog's out)

xxx@x3$ ./foo

File System                          bytes        used   available
capacity	accts

----------------------------------------------------------------------------
--
/global/ds/xp45                    200G        139G         59G
71%	1407
/global/ds/xp40                    200G        131G         67G
66%	1496
/global/ds/xp51                   200G        129G         69G
66%	1503
/global/ds/xp49                   200G        133G         65G
68%	1524


Thanks again!
sg

Report this thread to moderator Post Follow-up to this message
Old Post
spacegoose
03-21-08 11:59 PM


Re: matching column variables from two awks!
OK, let's try it this way. Look:

$ cat df_out
/dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/xp20
/dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/xp21
/dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/xp22
/dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/xp23
/dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/xp24
/dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/xp25
/dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/xp26
/dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/xp27
$
$ cat myFile
11     621 2008/03/21 12:44 xp20            256000 user/foo/INBOX
806   41722 2008/03/21 13:26 xp21            256000 user/bar/INBOX
2391  115428 2008/03/21 13:26 xp22            256000 user/moo/INBOX
2452  122771 2008/03/21 12:38 xp23            256000 user/123/INBOX
638   65484 2008/03/21 12:56 xp23            256000 user/345/INBOX
139    4892 2008/03/21 12:44 xp24            256000 user/789/INBOX
398   13403 2008/03/19 14:05 xp24            256000 user/1234/INBOX
392   32448 2008/03/21 14:14 xp25            256000 user/5678/INBOX
$
$ cat tst.awk
BEGIN {
printf "%-15s%12s%10s%10s%10s%10s\n", "File System", "bytes", "used", "avail
",
"capacity", "accounts"
print "-------------------------------------------------------------------"
}
NR==FNR{ accts["/local/ds/"$5]++; next }
/dsk/ { printf "%-15s%12s%10s%10s%10s%10s\n", $6, $2, $3, $4, $5, accts[$6]+
0 }
$
$ cat df_out | awk -f tst.awk myFile -
File System           bytes      used     avail  capacity  accounts
-------------------------------------------------------------------
/local/ds/xp20         200G      129G       69G       66%         1
/local/ds/xp21         200G      135G       63G       69%         1
/local/ds/xp22         200G      148G       50G       75%         1
/local/ds/xp23         200G      128G       70G       65%         2
/local/ds/xp24         200G      126G       72G       64%         2
/local/ds/xp25         200G      136G       62G       69%         1
/local/ds/xp26         200G      129G       69G       66%         0
/local/ds/xp27         200G      130G       68G       66%         0

Is that what you wanted?

If so, just replace "cat df_out" with "df -h | sort +5" (no need for grep):

df -h | sort +5 | awk -f tst.awk myFile -

If not, what are you looking for?

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-21-08 11:59 PM


Re: matching column variables from two awks!
On Mar 21, 6:32 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> OK, let's try it this way. Look:
>
> $ cat df_out
> /dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/xp20
> /dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/xp21
> /dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/xp22
> /dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/xp23
> /dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/xp24
> /dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/xp25
> /dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/xp26
> /dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/xp27
> $
> $ cat myFile
>     11     621 2008/03/21 12:44 xp20            256000 user/foo/INBOX
>    806   41722 2008/03/21 13:26 xp21            256000 user/bar/INBOX
>   2391  115428 2008/03/21 13:26 xp22            256000 user/moo/INBOX
>   2452  122771 2008/03/21 12:38 xp23            256000 user/123/INBOX
>    638   65484 2008/03/21 12:56 xp23            256000 user/345/INBOX
>    139    4892 2008/03/21 12:44 xp24            256000 user/789/INBOX
>    398   13403 2008/03/19 14:05 xp24            256000 user/1234/INBOX
>    392   32448 2008/03/21 14:14 xp25            256000 user/5678/INBOX
> $
> $ cat tst.awk
> BEGIN {
> printf "%-15s%12s%10s%10s%10s%10s\n", "File System", "bytes", "used", "ava
il",
> "capacity", "accounts"
> print "-------------------------------------------------------------------
"}
>
> NR==FNR{ accts["/local/ds/"$5]++; next }
> /dsk/ { printf "%-15s%12s%10s%10s%10s%10s\n", $6, $2, $3, $4, $5, accts[$6
]+0 }
> $
> $ cat df_out | awk -f tst.awk myFile -
> File System           bytes      used     avail  capacity  accounts
> -------------------------------------------------------------------
> /local/ds/xp20         200G      129G       69G       66%         1
> /local/ds/xp21         200G      135G       63G       69%         1
> /local/ds/xp22         200G      148G       50G       75%         1
> /local/ds/xp23         200G      128G       70G       65%         2
> /local/ds/xp24         200G      126G       72G       64%         2
> /local/ds/xp25         200G      136G       62G       69%         1
> /local/ds/xp26         200G      129G       69G       66%         0
> /local/ds/xp27         200G      130G       68G       66%         0
>
> Is that what you wanted?

yes - it's what i want - but making those files on my machine - and
running:

cat df_out | awk -f tst.awk myFile -

produces this:



File System           bytes      used     avail  capacity  accounts
-------------------------------------------------------------------
/local/ds/xp20         200G      129G       69G       66%         0
/local/ds/xp21         200G      135G       63G       69%         0
/local/ds/xp22         200G      148G       50G       75%         0
/local/ds/xp23         200G      128G       70G       65%         0
/local/ds/xp24         200G      126G       72G       64%         0
/local/ds/xp25         200G      136G       62G       69%         0
/local/ds/xp26         200G      129G       69G       66%         0
/local/ds/xp27         200G      130G       68G       66%         0


>
> If so, just replace "cat df_out" with "df -h | sort +5" (no need for grep)
:
>
>         df -h | sort +5 | awk -f tst.awk myFile -
>
> If not, what are you looking for?
>
>         Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
spacegoose
03-22-08 08:58 AM


Re: matching column variables from two awks!

On 3/22/2008 12:00 AM, spacegoose wrote:
> On Mar 21, 6:32 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> 
>
>
> yes - it's what i want - but making those files on my machine - and
> running:
>
> cat df_out | awk -f tst.awk myFile -
>
> produces this:
>
>
>
> File System           bytes      used     avail  capacity  accounts
> -------------------------------------------------------------------
> /local/ds/xp20         200G      129G       69G       66%         0
> /local/ds/xp21         200G      135G       63G       69%         0
> /local/ds/xp22         200G      148G       50G       75%         0
> /local/ds/xp23         200G      128G       70G       65%         0
> /local/ds/xp24         200G      126G       72G       64%         0
> /local/ds/xp25         200G      136G       62G       69%         0
> /local/ds/xp26         200G      129G       69G       66%         0
> /local/ds/xp27         200G      130G       68G       66%         0
>

That seems impossible.

Are you SURE you copy/pasted what I posted into files rather than retyping i
t? I
suspect your version of "myFile" is NOT the same one I posted.

Do this:

cat df_out
cat myFile
awk '{print FILENAME,$FNR,$0}' myFile df_out

and copy/paste the result into a posting so we can see what you're working w
ith.

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-22-08 12:58 PM


Re: matching column variables from two awks!

> That seems impossible.
>
> Are you SURE you copy/pasted what I posted into files rather than retyping
 it? I
>  suspect your version of "myFile" is NOT the same one I posted.
>
> Do this:
>
> cat df_out
> cat myFile
> awk '{print FILENAME,$FNR,$0}' myFile df_out
>
> and copy/paste the result into a posting so we can see what you're working
 with.
>
>         Ed.

I am running Solaris 10. Also tried on Solaris 9 -same result.

xxx@x3$ cat df_out
/dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/xp20
/dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/xp21
/dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/xp22
/dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/xp23
/dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/xp24
/dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/xp25
/dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/xp26
/dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/xp27


xxx@x3$  cat myFile
11     621 2008/03/21 12:44 xp20            256000 user/foo/INBOX
806   41722 2008/03/21 13:26 xp21            256000 user/bar/INBOX
2391  115428 2008/03/21 13:26 xp22            256000 user/moo/INBOX
2452  122771 2008/03/21 12:38 xp23            256000 user/123/INBOX
638   65484 2008/03/21 12:56 xp23            256000 user/345/INBOX
139    4892 2008/03/21 12:44 xp24            256000 user/789/INBOX
398   13403 2008/03/19 14:05 xp24            256000 user/1234/INBOX
392   32448 2008/03/21 14:14 xp25            256000 user/5678/INBOX




xxx@x3$ awk '{print FILENAME,$FNR,$0}' myFile df_out
myFile 11     621 2008/03/21 12:44 xp20            256000 user/foo/
INBOX 11     621 2008/03/21 12:44 xp20            256000 user/foo/
INBOX
myFile 806   41722 2008/03/21 13:26 xp21            256000 user/bar/
INBOX 806   41722 2008/03/21 13:26 xp21            256000 user/bar/
INBOX
myFile 2391  115428 2008/03/21 13:26 xp22            256000 user/moo/
INBOX 2391  115428 2008/03/21 13:26 xp22            256000 user/moo/
INBOX
myFile 2452  122771 2008/03/21 12:38 xp23            256000 user/123/
INBOX 2452  122771 2008/03/21 12:38 xp23            256000 user/123/
INBOX
myFile 638   65484 2008/03/21 12:56 xp23            256000 user/345/
INBOX 638   65484 2008/03/21 12:56 xp23            256000 user/345/
INBOX
myFile 139    4892 2008/03/21 12:44 xp24            256000 user/789/
INBOX 139    4892 2008/03/21 12:44 xp24            256000 user/789/
INBOX
myFile 398   13403 2008/03/19 14:05 xp24            256000 user/1234/
INBOX 398   13403 2008/03/19 14:05 xp24            256000 user/1234/
INBOX
myFile 392   32448 2008/03/21 14:14 xp25            256000 user/5678/
INBOX  392   32448 2008/03/21 14:14 xp25            256000 user/5678/
INBOX
myFile
df_out /dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/
xp20 /dev/md/ds/dsk/x20   200G   129G    69G    66%    /local/ds/xp20
df_out /dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/
xp21 /dev/md/ds/dsk/x21   200G   135G    63G    69%    /local/ds/xp21
df_out /dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/
xp22 /dev/md/ds/dsk/x22   200G   148G    50G    75%    /local/ds/xp22
df_out /dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/
xp23 /dev/md/ds/dsk/x23   200G   128G    70G    65%    /local/ds/xp23
df_out /dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/
xp24 /dev/md/ds/dsk/x24   200G   126G    72G    64%    /local/ds/xp24
df_out /dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/
xp25 /dev/md/ds/dsk/x25   200G   136G    62G    69%    /local/ds/xp25
df_out /dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/
xp26 /dev/md/ds/dsk/x26   200G   129G    69G    66%    /local/ds/xp26
df_out /dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/
xp27  /dev/md/ds/dsk/x27   200G   130G    68G    66%    /local/ds/xp27

also:

xxx@x3$ more tst.awk
BEGIN {
printf "%-15s%12s%10s%10s%10s%10s\n", "File System", "bytes", "used",
"avail", "capacity", "accounts"
print
"-------------------------------------------------------------------"
}

NR==FNR{ accts["/local/ds/"$5]++; next }
/dsk/ { printf "%-15s%12s%10s%10s%10s%10s\n", $6, $2, $3, $4, $5,
accts[$6]+0 }

Thanks,
sg

Report this thread to moderator Post Follow-up to this message
Old Post
spacegoose
03-22-08 11:58 PM


Re: matching column variables from two awks!
On 3/22/2008 9:37 AM, spacegoose wrote:
> I am running Solaris 10. Also tried on Solaris 9 -same result.

Ahh, you're using old, broken awk (/usr/bin/awk on Solaris). Use a modern aw
k,
e.g. GNU awk (gawk), New awk (nawk) or /usr/xpg4/bin/awk on Solaris.

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-22-08 11:58 PM


Re: matching column variables from two awks!
In article <47E59349.30308@lsupcaemnt.com>,
Ed Morton  <morton@lsupcaemnt.com> wrote:
>On 3/22/2008 9:37 AM, spacegoose wrote: 
>
>Ahh, you're using old, broken awk (/usr/bin/awk on Solaris). Use a modern a
wk,
>e.g. GNU awk (gawk), New awk (nawk) or /usr/xpg4/bin/awk on Solaris.
>
>	Ed.
>

This thread went on for quite a while, didn't it?

Amazing how many of these back-and-forths eventually boil down to:
Oh, by the way, I'm using Solaris.

(And if not that, the other one is: Oh, I'm writing the code on a
Windows box [and running/testing it on Unix])


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
03-22-08 11:58 PM


Re: matching column variables from two awks!

On 3/22/2008 6:23 PM, Kenny McCormack wrote:
> In article <47E59349.30308@lsupcaemnt.com>,
> Ed Morton  <morton@lsupcaemnt.com> wrote:
> 
>
>
> This thread went on for quite a while, didn't it?
>
> Amazing how many of these back-and-forths eventually boil down to:
> Oh, by the way, I'm using Solaris.
>
> (And if not that, the other one is: Oh, I'm writing the code on a
> Windows box [and running/testing it on Unix])
>

The other biggy is "post sample input and expected output". I always forget 
to
say "post sample input and THE expected output FROM THAT INPUT". Got to reme
mber
that....

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-23-08 03:01 AM


Re: matching column variables from two awks!
On Mar 22, 7:44 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 3/22/2008 6:23 PM, Kenny McCormack wrote:
>
>
> 
> 
> 
> 
> 
> 
> 
> 
>
> The other biggy is "post sample input and expected output". I always forge
t to
> say "post sample input and THE expected output FROM THAT INPUT". Got to re
member
> that....
>
>         Ed.

That did it. Thanks. One last thing: Can this be combined into one
file to act on myFile:
so that everything is contained in one file (with a reference to
myFile inside)?

Report this thread to moderator Post Follow-up to this message
Old Post
spacegoose
03-23-08 09:00 AM


Re: matching column variables from two awks!
On 3/23/2008 12:13 AM, spacegoose wrote:
<snip>
> That did it. Thanks. One last thing: Can this be combined into one
> file to act on myFile:
> so that everything is contained in one file (with a reference to
> myFile inside)?

I think what you want is to put this in a file:

------------
df -h | sort +5 | awk '
BEGIN {
printf "%-15s%12s%10s%10s%10s%10s\n", "File System", "bytes", "used", "avail
",
"capacity", "accounts"
print "-------------------------------------------------------------------"
}
NR==FNR{ accts["/local/ds/"$5]++; next }
/dsk/ { printf "%-15s%12s%10s%10s%10s%10s\n", $6, $2, $3, $4, $5, accts[$6]+
0 }
' myFile -
-------------

Regards,

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-23-08 09:00 AM


Sponsored Links




Last Thread Next Thread Next
Pages (3): « 1 [2] 3 »
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.