- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- getting data to the end of a line
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 03:26 AM
11-23-2007 03:26 AM
I would like some help on getting all information from a line after a certain string:
# id user
uid= (user) gid= (grp) groups=(grp),(grp),30331(grp),(grp),(grp), etc etc
I want to count how many grps a user is in by using awk so how do I get awk to display all information and including the field groups=(grp).
# awk -F',' '???????? {print NF}'
thanks in advance.
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 03:52 AM
11-23-2007 03:52 AM
Solutionawk -F"groups=" '{n=split($2,a,",")}; END {for (i=1;i<=n;i++) print i "-" a[i]}' f1
this is the result:
salvador/home/galbiati/> cat f1
uid= (user) gid= (grp) groups=(grp1),(grp2),30331(grp3),(grp4),(grp5)
salvador/home/galbiati/> awk -F"groups=" '{n=split($2,a,",")}; END {for (i=1;i<=n;i++) print i "-" a[i]}' f1
1-(grp1)
2-(grp2)
3-30331(grp3)
4-(grp4)
5-(grp5)
salvador/home/galbiati/>
if you want format the output fill free to change the last print.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 03:53 AM
11-23-2007 03:53 AM
Re: getting data to the end of a line
iduser=$(id user)
groups="groups${iduser#*groups}"
print $groups
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 03:59 AM
11-23-2007 03:59 AM
Re: getting data to the end of a line
id -G, or the groups command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:04 AM
11-23-2007 04:04 AM
Re: getting data to the end of a line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:05 AM
11-23-2007 04:05 AM
Re: getting data to the end of a line
Shoould do...
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:22 AM
11-23-2007 04:22 AM
Re: getting data to the end of a line
probably the easy way is to use the shell
${parameter#pattern}
${parameter##pattern}
If the shell pattern matches the beginning of the value of parameter, the value of this substitution is the value of the parameter with the matched portion deleted; otherwise the value of this parameter is substituted. In the former case, the smallest matching pattern is deleted; in the latter case, the largest matching pattern is deleted.
${parameter%pattern}
${parameter%%pattern}
If the shell pattern matches the end of the value of parameter, the value of parameter with the matched part is deleted; otherwise substitute the value of parameter. In the former, the smallest matching pattern is deleted; in the latter, the largest matching pattern is deleted.
Where the form of the patterns is the Pattern Matching Notation defined by regexp(5).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:23 AM
11-23-2007 04:23 AM
Re: getting data to the end of a line
if the context does not allow the use of the groups command, try the following. Having only a SUN at hand now, I see
id -a
uid=466(ef3nip00) gid=1710(nsd) groups=1710(nsd),232(audmcumc),1500(m2nck)
and use
id -a | awk '{g=split($3,a,",");print $1,$2,g"_"$3}'
to get the number of groups "3" inserted:
uid=466(ef3nip00) gid=1710(nsd) 3_groups=1710(nsd),232(audmcumc),1500(m2nck)
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:26 AM
11-23-2007 04:26 AM
Re: getting data to the end of a line
The credit goes to Arturo. I simple want to debug and show the beauty of one-liner in 3 -steps.
xyz.abc.com> id
uid=5133(rc_prd) gid=17425(rc_prd) groups=17425(rc_prd),2337(bdlexch),6075(xcollftp),18660(svc_ficd)
xyz.abc.com> id|awk -F "groups=" '{print $2}'
17425(rc_prd),2337(bdlexch),6075(xcollftp),18660(svc_ficd)
xyz.abc.com> id|awk -F"groups=" '{n=split($2,a,",")}; END {for (i=1;i<=n;i++) print i "-" a[i]}'
1-17425(rc_prd)
2-2337(bdlexch)
3-6075(xcollftp)
4-18660(svc_ficd)
Thanks,
Srikanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2007 04:30 AM
11-23-2007 04:30 AM
Re: getting data to the end of a line
Blah2blah - thanks for the detailed functionality.
have a nice weekend
Chris.