Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PERL variable conundrum 9 84
Regular Expression for URL 10 80
XPath Syntax help in conjunction with perl XML::LibXML 18 95
Perl tar error 8 31
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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now