count alphabets in a flat file and print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count alphabets in a flat file and print
# 1  
Old 04-21-2010
Question count alphabets in a flat file and print

I have a text file with a huge dataset, and each row in that dataset has some data(65479 rows). In that file I need to find the number of times a-z & A-Z Appears.

How Can I Initialise Array into an Array to parse the count also I need to parse a,A into a single array preferably.

example of the text file is as follows:

forum
flat
File

in this no.of "f" occourance count, it should result in 3.
# 2  
Old 04-21-2010
Code:
while(<DATA>)  {
        tr/A-Z/a-z/;
        foreach ( split //, $_ )  {
                $hash{$_}++;
        }
}

print "$_ => $hash{$_}\n" foreach ( keys %hash );


__DATA__
forum
flat
File

# 3  
Old 04-21-2010
Quote:
Originally Posted by thegeek
Code:
while(<DATA>)  {
        tr/A-Z/a-z/;
        foreach ( split //, $_ )  {
                $hash{$_}++;
        }
}
 
print "$_ => $hash{$_}\n" foreach ( keys %hash );
 
 
__DATA__
forum
flat
File

Thx geek!
# 4  
Old 04-21-2010
Code:
$
$ cat f3
forum
flat
File
$
$ perl -lne '$x{$_}++ foreach(split//,lc); END{print "$k => $v" while (($k,$v)=each %x)}' f3
e => 1
a => 1
r => 1
m => 1
l => 2
u => 1
f => 3
i => 1
o => 1
t => 1
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Count multiple columns and print original file

Hello, I have two tab files with headers File1: with 4 columns header1 header2 header3 header4 44 a bb 1 57 c ab 4 64 d d 5 File2: with 26 columns header1.. header5 header6 header7 ... header 22...header26 id1 44 a bb id2 57 ... (6 Replies)
Discussion started by: nans
6 Replies

2. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

3. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. Shell Programming and Scripting

Print combinations of alphabets in a sequence

Hi Friends, I have a series of alphabets like this AGCAA The values inside the square brace indicate that either of them can be present at that position. And those ones without a brace, means that they are the only ones that could be printed at that location. Now, I would like to know... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

5. Shell Programming and Scripting

Print record count of a file using shell script

HI, I need to print the record count of a file using shell script. If the record count of a file excluding header and trailer record if greater than zero then print 'Record count of a file is xxxx records'. If the record count is zero print 'zero records' Thanks Mahendra (1 Reply)
Discussion started by: mmeda
1 Replies

6. Shell Programming and Scripting

Unable to Print Count

Hi All, I am performing addition of two inetger variables which assigning output to a new variable getting following error. Check1.sh #!/bin/ksh filesrc=/usr/kk/Source1.txt filetgt=/usr/kk/Source2.txt FINAL_COUNTS= `awk '{n++} END {printf "%012d\n",n}' ${filesrc} ${filetgt}`... (3 Replies)
Discussion started by: kmsekhar
3 Replies

7. Shell Programming and Scripting

Unique count from flat file

Hello Guys I have a flat file with '|~|' delimited When I use to record count using below command awk -FS"+" ' {print $colno}' filename | wc -l the count is fine But when I am trying to find the unique number of record the o/p is always 1 awk -FS"+" ' {print $colno}'... (11 Replies)
Discussion started by: Pratik4891
11 Replies

8. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

9. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

10. Shell Programming and Scripting

Help with pipe count in a flat file!!!

Hi Friends, I have a flat file and it has 43 columns which means 42 pipes but some records have less number of pipes.Can anyone tell me a command to count the number of pipes in a record and redirect the count to some new file because the flat file has not less than 40,000 records. Thanks... (14 Replies)
Discussion started by: kumarsaravana_s
14 Replies
Login or Register to Ask a Question