Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Counting feilds entries with Perl Post 302510070 by pludi on Friday 1st of April 2011 12:56:04 PM
Old 04-01-2011
Given your data is in 'file.txt':
Code:
#!/usr/bin/perl -w

use strict;
use warnings;

my ( $data, %count );

{

    # Slurp in all data at once
    local $/;
    open my $fh, '<', 'file.txt' or die "Can't open file.txt: $!";
    $data = <$fh>;
    close $fh;
}

# Remove any line breaks, spaces, tabs, ...
$data =~ s/[\s]//msg;

# Split between each character, and sum the occurences
$count{$_}++ foreach ( split( //, $data ) );

# Print a sorted list of characters and their occurences
print "$_=$count{$_} " foreach sort keys %count;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need to insert two columns (or two feilds) at the begining of the table

Hey guys/gals, So here is what i'm starting with...its a Solaris patch diag output. bash-3.0# pca -l Using /var/tmp/patchdiag.xref from Oct/20/08 Host: seiftsx4140 (SunOS 5.10/Generic_127128-11/i386/i86pc) List: missing Patch IR CR RSB Age Synopsis ------ -- - -- --- ---... (3 Replies)
Discussion started by: zeekblack
3 Replies

2. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

3. Shell Programming and Scripting

Counting multiple entries in a file using awk

Hi, I have a big file (~960MB) having epoch time values (~50 million entries) which looks like 897393601 897393601 897393601 897393601 897393602 897393602 897393602 897393602 897393602 897393603 897393603 897393603 897393603 and so on....each time stamp has more than one... (6 Replies)
Discussion started by: sajal.bhatia
6 Replies

4. Shell Programming and Scripting

Counting duplicate entries in a file using awk

Hi, I have a very big (with around 1 million entries) txt file with IPv4 addresses in the standard format, i.e. a.b.c.d The file looks like 10.1.1.1 10.1.1.1 10.1.1.1 10.1.2.4 10.1.2.4 12.1.5.6 . . . . and so on.... There are duplicate/multiple entries for some IP... (3 Replies)
Discussion started by: sajal.bhatia
3 Replies

5. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

6. Shell Programming and Scripting

counting words with perl?

how to use perl to count number of lines, words characters in a file. (3 Replies)
Discussion started by: winter9
3 Replies

7. Shell Programming and Scripting

Counting entries in a file

Hi, I have a very large two column log file in the following format: # Epoch Time IP Address 899726401 112.254.1.0 899726401 112.254.1.0 899726402 154.162.38.0 899726402 160.114.12.0 899726402 165.161.7.0 899726403 ... (39 Replies)
Discussion started by: sajal.bhatia
39 Replies

8. Shell Programming and Scripting

Perl: Counting matches

Hi, A perl newbie here so pretty sure it's something simple. Trying to figure out how to count matches with perl pattern matching. The following script opens a text data file and finds lines containing "PORT:" and I'd like to count how many of these are found. Any ideas? open(LOG,"<... (3 Replies)
Discussion started by: hdefjunkie
3 Replies

9. Shell Programming and Scripting

Word counting perl script

Hi friends i need a help on Perl Script In My Home directory, i have some other directories and inside those directories i have some subdirectories and all the directories contains files. Now i want to count a word in all files and i want the output like below wordcount in which file(name... (5 Replies)
Discussion started by: siva kumar
5 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
doctools::changelog(n)						Documentation tools					    doctools::changelog(n)

__________________________________________________________________________________________________________________________________________________

NAME
doctools::changelog - Processing text in Emacs ChangeLog format SYNOPSIS
package require Tcl 8.2 package require textutil package require doctools::changelog ?1? ::doctools::changelog::scan text ::doctools::changelog::toDoctools title module version entries ::doctools::changelog::merge entries... _________________________________________________________________ DESCRIPTION
This package provides Tcl commands for the processing and reformatting of text in the "ChangeLog" format generated by emacs. API
::doctools::changelog::scan text The command takes the text and parses it under the assumption that it contains a ChangeLog as generated by emacs. It returns a data structure describing the contents of this ChangeLog. This data structure is a list where each element describes one entry in the ChangeLog. Each element/entry is then a list of three elements describing the date of the entry, its author, and the comments made, in this order. The last item in each element/entry, the comments, is a list of sections. Each section is described by a list containing two elements, a list of file names, and a string containing the true comment associated with the files of the section. { { date author { { {file ...} commenttext } ... } } {...} } ::doctools::changelog::toDoctools title module version entries This command converts the pre-parsed ChangeLog entries as generated by the command ::doctools::changelog::scan into a document in doctools format and returns it as the result of the command. The other three arguments supply the information for the header of that document which is not available from the changelog itself. ::doctools::changelog::merge entries... Each argument of the command is assumed to be a pre-parsed Changelog as generated by the command ::doctools::changelog::scan. This command merges all of them into a single structure, and collapses multiple entries for the same date and author into a single entry. The new structure is returned as the result of the command. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category doctools of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
changelog, doctools, emacs COPYRIGHT
Copyright (c) 2003-2008 Andreas Kupries <andreas_kupries@users.sourceforge.net> doctools 1 doctools::changelog(n)
All times are GMT -4. The time now is 07:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy