Hello Every one ,
Pls help me to extracting number from a text file since I am new to perl programming .
I have a file and need to extract the number after semicolon in that
-----------------Contents of the file ----------------------- -
Total Number Of Inputs From Rajasthan is: 1675
-
Total Number Of Subscriber Successfully Provisioned for RAJASTHAN CIRCLE are : 1146
-
Total Number Of Unsuccessfull Provisioning for RAJASTHAN CIRCLE are : 527
-
Total Number Of Already Two Provisioned Entries are : 433
-
Total Number Of Not General Entries are : 1
-
Total Number Of Anant Entries are : 27
-
Total Number Of One Number Allowed Entries are : 7
-
Total Number Of Single Number Mobile Entries are : 23
-
Total Number Of Number Already Provisioned Entries are : 36
-
Total Number Of No Subscriber Entries are : 0
-
Total Number Of Invalid Input Number Entries are : 0
-
Total Number Of Both Mobile Entries are : 0
-
Total Number Of Indiaone Entries are : 0
-
Total Number Of Bundled Sim Entries are : 0
-
Total Number Of Free SMS Entries are : 0
-
Total Number Of Invalid LSA Entries are : 0
-
Total Number Of Preactive Entries are : 0
-
Total Number Of Student Power Entries are : 0
-
Total Number Of Not 91 Entries are : 0
-
Total Number Of More than Two Request Entries are : 0
-
Total Number Of No Request Entries are : 0
-
Total Number Of Not 6 Months Entries For New FnF Update Request are : 0
-
-
Total Number Of Inputs From Punjab is: 718
-
Total Number Of Subscriber Successfully Provisioned for PUNJAB CIRCLE are : 438
-
Total Number Of Unsuccessfull Provisioning for PUNJAB CIRCLE are : 280
-
Total Number Of Already Two Provisioned Entries are : 197
-
Total Number Of Not General Entries are : 3
-
Total Number Of Anant Entries are : 14
-
Total Number Of One Number Allowed Entries are : 3
-
Total Number Of Single Number Mobile Entries are : 34
-
Total Number Of Number Already Provisioned Entries are : 12
-
Total Number Of No Subscriber Entries are : 0
-
Total Number Of Invalid Input Number Entries are : 0
-
Total Number Of Both Mobile Entries are : 0
-
Total Number Of Indiaone Entries are : 0
-
Total Number Of Bundled Sim Entries are : 17
-
Total Number Of Free SMS Entries are : 0
-
Total Number Of Invalid LSA Entries are : 0
-
Total Number Of Preactive Entries are : 0
-
Total Number Of Student Power Entries are : 0
-
Total Number Of Not 91 Entries are : 0
-
Total Number Of More than Two Request Entries are : 0
-
Total Number Of No Request Entries are : 0
-
Total Number Of Not 6 Months Entries For New FnF Update Request are : 0
-
And the output should be like the following . -
1675 1146 527 433 1 27 7 23 36 0 0 0 0 0 0 0 0 0 0 0 0
-
-
718 438 280 197 3 14 3 34 12 0 0 0 0 17 0 0 0 0 0 0 0 0
-
I have written the following code but it's not working on the above file.
-----------------------------Code ----------------------------------- -
open(INPUT, "report.txt");
-
-
while (chop(my $Line =<INPUT>)) {
-
-
if( $Line =~ /Total Number Of Inputs From / ) {
-
print "\n" ;
-
}
-
-
($String, $Digit) = split /:/, $Line ;
-
-
print $Digit ;
-
}
-
-
6 2597
Hello Amma,
You are almost there. You simply needed to check to see if the $digit value existed to take into account blank lines, and then simply remove spaces from around the $digit value. -
use strict;
-
-
open (INPUT, "report.txt") or die "Cant open report.txt: $!";
-
-
while (my $line = <INPUT>) {
-
chomp $line;
-
-
if( $line =~ /Total Number Of Inputs From / ) {
-
print "\n";
-
}
-
-
my ($string, $digit) = split /:/, $line;
-
-
if ($digit ne '') {
-
$digit =~ s/\s+//g; # Removes spaces from around number
-
print "$digit ";
-
}
-
}
-
-
close INPUT;
-
- Miller
perl -pe 'chomp;print "\n" if $i++ && m/Total Number Of Inputs/;$_=(split/:/)[1];END {print "\n"}' report.txt
Hi...
use strict;
open (INPUT, "report.txt") or die "Cannot open report.txt: $!";
while (my $line = <INPUT>) {
$line=~s/([^:]+):([^\n]+)(\n)?/$2/sg;
print $line;
}
close(INPUT);
$line=~s/([^:]+):([^\n]+)(\n)?/$2/sg;
Gentlemen,
You're very amusing. However, the best way to help someone is to use their own code to show them how to finish a project.
One-liners, while nice to know, are rarely the best solution for a problem. But if you really want to create one: -
perl -pe 's/.*\b(\d+)\s*$/$1 /' report.txt
-
Output is: -
1675 1146 527 433 1 27 7 23 36 0 0 0 0 0 0 0 0 0 0 0 0 0
-
718 438 280 197 3 14 3 34 12 0 0 0 0 17 0 0 0 0 0 0 0 0
-
- Miller
-
perl -pe 's/.*\b(\d+)\s*$/$1 /' report.txt
-
hi..
that was imporesting :-)
can you please describe for me what
perl -pe 's/.*\b(\d+)\s*$/$1 /' report.txt
does ? part by part.
thanx
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
Hi,
I have a very long string, someting like:
DISPLAY=localhost:0.0,FORT_BUFFERED=true,
F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
|
by: Avi |
last post by:
hi,
Can anyone tell me what the problem is and how to solve it
The following piece of code resides on an asp page on the server and
is used to download files from the server to the machine...
|
by: Nadav |
last post by:
Hi,
Introduction:
***************************
I am using the MSI API to extract MSI embedded files, I do this by iterating
through all of the records in the ‘_Streams’ table and dumping...
|
by: Randy |
last post by:
Is there any way to do this? I've tried tellg() followed by seekg(),
inserting the stream buffer to an ostringstream (ala os << is.rdbuf()),
read(), and having no luck.
The problem is, all of...
|
by: Sunil Basu |
last post by:
Hi,
I have a interesting thing to know and discuss with you.
I am extracting data from an Excel file in a Delphi DbGrid through SQL. I want to create a criteria on a specific cell value of the...
|
by: sgsiaokia |
last post by:
I need help in extracting data from another source file using VBA. I have problems copying the extracted data and format into the required data format. And also, how do i delete the row that is not...
|
by: rlntemp-gng |
last post by:
I need to extract information from some Excel files but am stuck with
part of it:
As an example, I have the following Excel File that has 3 tabbed
sheets:
FileName: ...
|
by: Werner |
last post by:
Hi,
I try to read (and extract) some "self extracting" zipefiles on a
Windows system. The standard module zipefile seems not to be able to
handle this.
False
Is there a wrapper or has...
|
by: poolboi |
last post by:
hi guys
i've having some problem extracting data from a text file
example if i got a text file with infos like:
Date 2008-05-01 Time 22-10
Date 2008-05-01 Time 21-00
Date 2008-05-02 Time...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |