Solved

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

Posted on 2013-06-25
2
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

707 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