- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sed to remove comma
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-30-2002 01:02 AM
11-30-2002 01:02 AM
Sed to remove comma
Group1::101:user1,users,user3,user4,user4
to
Group::101:
The following command
sed -e 's/'$username'//' -e '/,$//' /etc/group
not working
Here's the output
Group1:::101:,,,,
Thanks
Aravind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 01:57 AM
11-30-2002 01:57 AM
Re: Sed to remove comma
cat /etc/group|sed 's/:/ /g'|sed 's/,/ /g'|awk '{print $1"::"$2":"}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 04:56 AM
11-30-2002 04:56 AM
Re: Sed to remove comma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 07:03 AM
11-30-2002 07:03 AM
Re: Sed to remove comma
sed 's/\(.*:\).*/\1/'/etc/group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 08:18 AM
11-30-2002 08:18 AM
Re: Sed to remove comma
First, presuming you mean to delete one command from the end of the line, it appears your second expression should be:
-e 's/,$//'
I assume you are executing this in a loop and passing a different value for $username each time. If so, you have 4 possible cases (assume $username = user1):
1) $username is the only user in the group
Group1:::101:user1
2) $username is the first of several users in the group
Group1:::101:user1,user2,user3
3) $username is the last of several users in the group
Group1:::101:user3,user2,user1
4) $username is neither first nor last of several users in the group
Group1:::101:user2,user1,user3
Your sed statement needs to allow for each possibility. One method would be:
sed -e 's/'$username'//' -e 's/:,/:/' -e 's/,$//' -e 's/,,/,/' /etc/group
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 08:20 AM
11-30-2002 08:20 AM
Re: Sed to remove comma
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2002 07:52 PM
11-30-2002 07:52 PM
Re: Sed to remove comma
sed "s/^\(.*\)\:\:\(.*\)\:.*$/\1::\2:/"
or
sed "s/^\(.*\)\(\:.*$\)/\1:/"
both produce
# export OLINE="Group1::101:user1,users,user3,user4,user4"
# echo $OLINE | sed "s/^\(.*\)\(\:.*$\)/\1:/"
Group1::101:
# echo $OLINE | sed "s/^\(.*\)\:\:\(.*\)\:.*$/\1::\2:/"
Group1::101:
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 08:18 AM
12-09-2002 08:18 AM
Re: Sed to remove comma
have you tried putting the comma after the username you want to remove?
sed -e 's/'$username'[,]*//' /etc/group
should remove the comma if it exists, and work when there is no comma...
Cheers,
Fran??ois-Xavier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2002 08:45 AM
12-09-2002 08:45 AM
Re: Sed to remove comma
sed 's/:[^:]*$/:/' /etc/group
Rgds, Robin