Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-25
2
Medium Priority
?
311 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

604 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