Sorry about the previous wrong example. For GAWK the format is a little
bit different than the AWK format. Here is the GAWK format:
gawk -F":" '{if($1 == ZZ) { print $6 }}' -v "ZZ=${username}" passwd.bak
>output
If needed two arguments passed in you would have to give another -v
preceeding the double-quote surrounded variable and it's value, ie.,
"YY=12345" , ie. :
gawk -F":" '{if($1 == ZZ) { print $6 } ; if(YY == $4) { print $6 }}' -v
"ZZ=${username}" -v "YY=12345" passwd.bak >output
You may want to put the script into a file (say filename "space.gwk"
) and try it like the below:
gawk -F":" -f space.gwk -v "ZZ=${username}" passwd.bak >output
_____
From: geeksthatgawk@yahoogroups.com
[mailto:geeksthatgawk@yahoogroups.com] On Behalf Of Stout, Danny
Sent: Tuesday, December 27, 2005 7:55 AM
To: geeksthatgawk@yahoogroups.com
Subject: RE: [Geeks that Gawk] Re: Help On awk
Or might try this one:
awk -F":" '{if($1 == ZZ){print $6}}' ZZ=${username}
passwd.bak >output
_____
From: geeksthatgawk@yahoogroups.com
[mailto:geeksthatgawk@yahoogroups.com] On Behalf Of Adam
Sent: Monday, December 26, 2005 7:09 PM
To: geeksthatgawk@yahoogroups.com
Subject: [Geeks that Gawk] Re: Help On awk
I'm not sure, but
it looks like the apostrophies get in the way.
try:
awk -f":" '/'$username'/ { print $6 }' passwd.bak >output
I hope that works.
--- In geeksthatgawk@yahoogroups.com, renuka prasad
<renukaprasadtg@y...> wrote:
>
> Hi All,
>
> I need a help from u.I'm getting the home directory
> from passwd.bak file.I need to find the disk usage of
> that particular user.I'm getting output if i directly
> substitue variable $username with exact username.But
> i'm not getting output when i use in shell script.The
> contents is as follows:
>
> ---------------------------------------------------------------------
> # Script for displaying diskusage based on user name
> # Only username to be supplied by user
> echo "\n Please enter the username:\c"
> read username
> awk -F":" '/$username/ { print $6 }' passwd.bak >
> output
> echo " Home Directory Of $username "
> cat output
> echo " Disk Usage in KB:"
> sudo du -sk < output
> ----------------------------------------------------------------------
> I really appreciate any kind of help on this.Thanks
> in advance.
>
> Regards,
> Prasad
>
>
>
>
> __________________________________
> Yahoo! for Good - Make a difference this year.
> http://brand.yahoo.com/cybergivingweek2005/
>
SPONSORED LINKS
Basic programming language
<http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic
+programming+language&w2=Computer+programming+languages&w3=Programming+l
anguages&w4=Java+programming+language&c=4&s=126&.sig=bnac3LCZpttb3c9FvbV
U-A>
Computer programming languages
<http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=B
asic+programming+language&w2=Computer+programming+languages&w3=Programmi
ng+languages&w4=Java+programming+language&c=4&s=126&.sig=1Czd2hKCO9_u4KV
ZQperFQ>
Programming languages
<http://groups.yahoo.com/gads?t=ms&k=Programming+languages&w1=Basic+prog
ramming+language&w2=Computer+programming+languages&w3=Programming+langua
ges&w4=Java+programming+language&c=4&s=126&.sig=TyHGCjod4YOKITrSq1xccQ>
Java programming language
<http://groups.yahoo.com/gads?t=ms&k=Java+programming+language&w1=Basic+
programming+language&w2=Computer+programming+languages&w3=Programming+la
nguages&w4=Java+programming+language&c=4&s=126&.sig=PZAexF9LyXpKb3HDJSlB
1g>
_____
YAHOO! GROUPS LINKS
* Visit your group "geeksthatgawk
<http://groups.yahoo.com/group/geeksthatgawk> " on the web.
* To unsubscribe from this group, send an email to:
geeksthatgawk-unsubscribe@yahoogroups.com
<mailto:geeksthatgawk-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
_____
[Non-text portions of this message have been removed]
_____
YAHOO! GROUPS LINKS
* Visit your group "geeksthatgawk
<http://groups.yahoo.com/group/geeksthatgawk> " on the web.
* To unsubscribe from this group, send an email to:
geeksthatgawk-unsubscribe@yahoogroups.com
<mailto:geeksthatgawk-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
_____
[Non-text portions of this message have been removed]