Solved

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

Posted on 2013-06-25
2
307 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

733 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