[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Request a perl one-liner to count matched patterns in a file

Posted on 2012-04-03
3
Medium Priority
?
302 Views
Last Modified: 2012-04-03
Request a perl to count matched patterns in a file. Is one-liner possible? The environment is ms windows. For example,
in test.txt,

aa bb 12 32 24 bc d1 ff f0 cc
24 bc d1 99 0f cd ab db ea 12
12 23 34 45 54 55 21 78 34 89
cd ae de ef ca cb da 24 bc d1
cd 24 bc d1 24 bc d1 ca cb da
.....

Want to count how many pattern "24 bc d1" in this file. Not need to consider the overlapped case such as the line 12 12 12 12 if the matched pattern is "12 12 12".
0
Comment
Question by:jl66
[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
3 Comments
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 400 total points
ID: 37801209
Something like

my $pattern = '24 bc d1';
$/ = undef;
my $text = <>;
my (@words) = $text =~ /$pattern/g;
print @words . "\n";
0
 
LVL 84

Accepted Solution

by:
ozo earned 1600 total points
ID: 37801488
perl -ne "BEGIN{$/='24 bc d1'}$c=chomp;END{print $.-!$c}" test.txt
0
 

Author Closing Comment

by:jl66
ID: 37801925
Thanks a lot for the solution.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

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.…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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

650 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