- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- check duplicate string
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
06-22-2006 01:50 PM
06-22-2006 01:50 PM
check duplicate string
aaa
bbb
ccc
ddd
eee
fff
ggg
aaa
the string "aaa" is duplicate , if I want to check any other duplicate string in the file , what can I do , can anyone help me ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 01:59 PM
06-22-2006 01:59 PM
Re: check duplicate string
This will output any duplicate lines. Man uniq for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 02:31 PM
06-22-2006 02:31 PM
Re: check duplicate string
For small files I like using perl (or awk) associative array. For example:
# perl -ne "print if $x{$_}++" x.txt
Or
# perl -ne "print if 1==$x{$_}++" x.txt
Or
perl -ne "if (1==$x{$_}++) { print "duplicate: $_" } " x.txt
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 10:08 PM
06-22-2006 10:08 PM
Re: check duplicate string
you can even the the number of times (double, triple, ...) , a duplicate string occurs:
sort FILE | uniq -dc
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 10:40 PM
06-22-2006 10:40 PM
Re: check duplicate string
sort filename | uniq -d
to just list the entries which are duplicate (This will not list entries which occur only once)
sort filename | uniq or simply sort -u filename to get unique entries (This will omit the duplicate entries while displaying)
sort filename | uniq -dc | grep -v " 1 "
This will display entries which are duplicate with the count of their occurances.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 10:48 PM
06-22-2006 10:48 PM
Re: check duplicate string
awk '{a[$0]++} END {for (k in a){v=a[k]; if (v>1) print k, v}}' x
awk '{array[$0]++} END {for (key in array){val=array[key]; if (val>1) print key "=" val}}' x
:-)
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2006 12:42 AM
06-23-2006 12:42 AM
Re: check duplicate string
cheers,
f. halili