|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help with awk to create report
Hi,
I am trying to create a report using the following syntax: #!/bin/awk -f #script name: users_report BEGIN { FS=":" ; OFS="\t" ; print "User\tGID\tUser Name\tHome Dir\t" { print $1 , $3 , $5 , $6 } END { print "\n End of Report \n" } $> user_report /etc/passwd the output of above code is as under: User GID User Name Home Dir jbond 500 James Bond /home/sales pdavid 501 Pierre Davidd /home/Marketing ... so on END of Report now trying to change the GID number to group name from /etc/group first filed. the output should look like this: User GID User Name Home Dir jbond SALES James Bond /home/sales pdavid Market Pierre Davidd /home/Market ... so on END of Report Can someone help me complet this code with awk or with any other appropriate command syntax please. Thanks in advance for your help. Regards, Ghazi |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
awk 'FS=":" { OFS="\t" }
BEGIN { print "User\tGID\tUser Name\tHome Dir" }
{ print $1,$3,$5,$6 }
END { print "\n End of the Report \n" }' /etc/passwd |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
echo "User\tGID\tUser Name\tHome Dir" cut -d":" -f 1,3,5,6 /etc/passwd | tr ":" "\t" echo "\nEnd of the Report \n" |
|
#5
|
||||
|
||||
|
I'll throw my script into the pot too... Code:
#!/bin/ksh
printf "%-9s%-20s%-25s%-10s\n" "User" "Group" "Full Name" "Home"
printf "%-9s%-20s%-25s%-10s\n" "----" "-----" "---------" "----"
while read line
do
gid=`echo $line | awk -F':' '{print $4}'`
group=`grep ":$gid:" /etc/group | cut -d':' -f 1`
echo "$line" | awk -vg=$group -vFS=':' '{ printf( "%-9s%-20s%-25s%-10s\n", $1, g, $5, $6 ) }'
done < /etc/passwd
echo "END OF REPORT"Cheers ZB |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thank you all. It really helped. It is a wonderful forum.
With best regards, Ghazi ![]() |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Create Report from shell | julien_83 | Shell Programming and Scripting | 3 | 10-08-2010 08:27 AM |
| How to format or create a matrix report from file | manas_ranjan | Shell Programming and Scripting | 3 | 12-24-2008 08:38 AM |
| using todays date to create a report using grep | MBN | Shell Programming and Scripting | 3 | 11-02-2008 03:14 AM |
| create a report using shell | moco | Shell Programming and Scripting | 10 | 04-12-2007 06:01 AM |
|
|