Solved

Perl count characters in a file that dont match A-Za-z0-9

Posted on 2013-06-25
2
306 Views
Last Modified: 2013-06-25
Hi,

I have a text file that I want to parse in perl.

From that file I want a count of each of the characters where the character isn't A-Z,a-z or 0-9.

e.g If my file just contained the following line:

##Hello, just - checking, this, string.##

Open in new window


I'd like the following output:
, 3
- 1
. 1
# 4

Open in new window


How can I process the file to achieve this?
0
Comment
Question by:yelbow
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39274039
Since you don't want the output
  5
, 3
- 1
. 1
# 4

Open in new window

I infer that you want only characters that don't match \sA-Za-z0
But I'm not sure how you are determining the order of the characters in your output.                                  
echo '##Hello, just - checking, this, string.##' | perl -lne '++$n{$_}for/[^\sA-Za-z0-9]/g;END{print "$_ $n{$_}" for sort{($a^"\10")cmp($b^"\10")}keys %n}'
0
 

Author Closing Comment

by:yelbow
ID: 39274095
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question