- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script to search more than 2 instances of same...
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
08-04-2009 12:56 PM
08-04-2009 12:56 PM
How to write script to print ONLY numbers which appear more than 2 times in a file below (numbers.txt).
So, output from from running thes scirpt (script.sh) after processing the txt file below should only show something like:
=================
#./script.sh
6 appears 3 times
1 appears 1 times
===================
numbers.txt
===========
12
12
111
111
6
6
6
1
22
22
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2009 01:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2009 01:11 PM
08-04-2009 01:11 PM
Re: script to search more than 2 instances of same number in text file?
# sort -n numbers.txt | uniq -c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2009 04:43 PM
08-04-2009 04:43 PM
Re: script to search more than 2 instances of same number in text file?
Thanks. It was simpler than I thougt. That is what I needed.
Appreciate it.
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2009 07:48 PM
08-04-2009 07:48 PM
Re: script to search more than 2 instances of same number in text file?
$ perl -ne 'chomp; $x{$_}++} { for (keys %x) {printf qq(%3d appears %3d times\n),$_,$x{$_}}' number.txt
22 appears 2 times
6 appears 3 times
1 appears 1 times
111 appears 2 times
12 appears 2 times
chomp; # take away new-line
$x{$_}++ # increment associative array element identified by line $_
} { # close input loop, open END block.
for (keys %x) { # what he said
printf qq(%3d appears %3d times\n) # formatted print
,$_,$x{$_} # variables are key and value for key
}' # close keys block, end program
number.txt # input stream.
hth,
Hein.