![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our 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 | Rate Thread | Display Modes |
|
|||
|
Trying to improve radoulov solution ![]() Code:
# cat /etc/group
hostname Groupname GID Userlist Date
myHot operaors 54 542 542 542 542 542 542 542 user1 user9 24/11/2009
myHost operators 542 542 542 542 542 542 542 542 user2 24/11/2009
myHost operators 542 542 542 542 542 542 542 542 user3 24/11/2009
myHost operators 542 542 542 542 542 542 542 542 user4 24/11/2009
myHost operators 542 542 542 542 542 542 542 542 user5 24/11/2009
myHost operators 542 542 542 542 542 542 542 542 user6 user7 24/11/2009
# awk -F'\t' 'NR>1{split($3, g, " ");n=split($4,u," ");for(i=0;++i<=n;){print $1,$2,g[1],u[i],$NF}next}1' OFS=\\t /etc/group
hostname Groupname GID Userlist Date
myHot operaors 54 user1 24/11/2009
myHot operaors 54 user9 24/11/2009
myHost operators 542 user2 24/11/2009
myHost operators 542 user3 24/11/2009
myHost operators 542 user4 24/11/2009
myHost operators 542 user5 24/11/2009
myHost operators 542 user6 24/11/2009
myHost operators 542 user7 24/11/2009
OP whould watch for Useless Use of Cat Award
|
|
|||
|
i'll reframe my problem...this should be easy to debug ... Code:
bash-3.00$ A=`cat /etc/group|awk -F: '{if ($1$3 == "secur138"){print $NF}}'|sort|uniq`
bash-3.00$ echo $A
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb,smadmn,sysweb,root
See that green colored string....rest all strings(or members) are comma separated....whereas this string is not..it should have been t6658pb,t9330sp... and its happening because Code:
bash-3.00$ cat /etc/group|awk -F: '{if ($1$3 == "secur138"){print $NF}}'
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb,smadmn,sysweb,root
i have two groups defined with same name and id ,but few diffrent members.... My code looks like following to capture these comma separated strings: Code:
Host etcGroup DUP:
cat /etc/group | awk -F':' '{print $1$3}'|sort|uniq
Userlist:
A=`cat /etc/group|awk -F: '{if ($1$3 == "@@Host etcGroup.DUP@@") {print $NF}}'|sort|uniq`
B=`echo $A|wc -w`
if [ $B = 0 ]
then
echo NULL
else
count=`echo $A| nawk -F, {'print NF'}`
i=1
while [ $i -le $count ]
do
str[$i]=`echo $A| cut -d, -f${i}`
echo "${str[$i]}"
i=`expr $i + 1`
done
fi
any ideas? Regards Abhi |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Secondary group info source | fmattos | SUN Solaris | 6 | 12-01-2009 08:19 AM |
| Merge group numbers and add a column containing group names | Lucky Ali | Shell Programming and Scripting | 3 | 11-20-2009 02:10 AM |
| retrieving all group names with a given group number | Andrewkl | UNIX for Advanced & Expert Users | 3 | 10-25-2008 05:07 AM |
| Monkcast #12: IBM HW group OEMs Solaris to chagrin of SW group & a ... - ZDNet.com bl | Linux Bot | UNIX and Linux RSS News | 0 | 08-17-2007 05:30 PM |
| entry in /etc/group too long - problem using sudo with %group | poli | SUN Solaris | 4 | 12-21-2004 09:50 AM |