- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Grep in a script
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
02-18-2002 01:07 AM
02-18-2002 01:07 AM
The answer to this is probably very simple but it is Monday morning so I appologise for being a bit dopey.
I am writing a script to search the passwd file for duplicate names. So far I have this:
cut -d: -f5 /etc/passwd |while read a
do
if [ grep -c $a /etc/passwd >1 ]
then
echo $a
fi
done
All I get when running this is 'A test command parameter is not valid' in line 4 (the grep command)
I know it is probably a simple syntax problem like I said, I've not quite woken up this morning.
Thanks in advance,
Christian Briddon
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:14 AM
02-18-2002 01:14 AM
Re: Grep in a script
Replace > with -gt and put the grep within grave accent and double quotes.
cut -d: -f5 /etc/passwd |while read a
do
if [ "`grep -c $a /etc/passwd`" -gt 1 ]
then
echo $a
fi
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:15 AM
02-18-2002 01:15 AM
Re: Grep in a script
I think your if should be
if [ $(grep -c $a /etc/passwd) >1 ]
Hope this helps,
Tom Geudens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:23 AM
02-18-2002 01:23 AM
Re: Grep in a script
cut -d: -f5 /etc/passwd | uniq -d
Print only duplicate lines
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:35 AM
02-18-2002 01:35 AM
Re: Grep in a script
Volker,
Last I knew, it was "short & sweet".
Your version gives it a nice twist, though!
:-)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:43 AM
02-18-2002 01:43 AM
Re: Grep in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:45 AM
02-18-2002 01:45 AM
Re: Grep in a script
Deepak,
actually it is not "mine" (no enlisted copyright).
I never heard of short & sweet before, but it's nice also.
;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 01:50 AM
02-18-2002 01:50 AM
Solutioncut -d: -f5 /etc/passwd | sort | uniq -c | grep -v "^ 1 "
will show you how many of each duplicate.
Keeping with your original script, modify it to:
cut -d: -f5 /etc/passwd |while read a
do
if [ `grep -c "$a" /etc/passwd` -gt 1 ]
then
echo $a
fi
done
Note the $a is quoted in case it's empty.
Rgds, Robin.