I am trying to write a script to do the following.
Go thru the file until it finds an expression ("9227493"). Once this expression is found, I want the script to search in a reverse fashion until it finds another string ("hopid"). And I want to save that line.
How would I go about doing this?
My file looks like this:
First Line
Second Line
third line hop 2746
fourth line
fifth line
sixth line
seventh Line 9227493abc
eighth Line
nineth line hop 8888
tenth line
eleventh line 9227493abc
twelvth line
The output will be:
2746
8888
Thank you in advance for your assistance.
Kalpesh
4 1917
If you don't know any perl I would start with a good perl book. Before others offer much assistance you will need to try and write the code yourself, or hire a programmer.
If you have a problem with your code please post it back and we will see what can be done to help.
--Kevin
What would be easier is to find hop, store the value you need, then keep going until you find 9227493 then print the value of hop. Repeat and continue until the end of the file.
Sorry, but simplest solution is: -
use strict;
-
use warnings;
-
-
my $file = 'text.txt';
-
open FILE, $file or die "can't open $file";
-
my @text = <FILE>;
-
close FILE;
-
-
my ( @ids ) = ( join '', @text ) =~ /hop (\d+)[^\d]+?9227493/g;
-
printf "%s\n", ( join "\n", @ids );
-
where text.txt contains user data
@RichKersh
While we definitely appreciate your helping out, this is a learning forum. The op has already been asked to provide their code if they got stuck, which tells them they need to at least try to code a solution.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Els |
last post by:
***newbie question***
Hi, I am trying to make my server (Apache) parse .html files
as .php.
I found this line of code:
ForceType application/x-httpd-php
placed it in an .htaccess file and...
|
by: Illya Havsiyevych |
last post by:
Hello
How easily parse VB/VBA code by VB/VBA code ?
Is any ready solutions ?
Thank's,
illya
|
by: Johnny Google |
last post by:
Here is an example of the type of data from a file I will have:
Apple,4322,3435,4653,6543,4652
Banana,6934,5423,6753,6531
Carrot,3454,4534,3434,1111,9120,5453
Cheese,4411,5522,6622,6641
The...
|
by: William Stacey [MVP] |
last post by:
Anyone know of some library that will parse files like following:
options {
directory "/etc";
allow-query { any; }; // This is the default
recursion no;
listen-on { 192.168.0.225;...
|
by: akira |
last post by:
Hello,
I need to parse this XML file or XML stream . Is it possible to parse
it with DOM reading each DataContainer one by one.
<DataContainer>
<name> </name>
<birthDate> </birthDate>...
|
by: Rob Meade |
last post by:
Hi all,
I'm working on a project where there are just under 1300 course files, these
are HTML files - my problem is that I need to do more with the content of
these pages - and the thought of...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming.
FYI
Although I have called...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming.
FYI
Although I have called this...
|
by: Baron Samedi |
last post by:
I have been searching, unsuccessfully, for a program which will parse
header files and generate stubs for all external declarations
(classes, functions, <shudderglobal variables).
I want this so...
|
by: jo3c |
last post by:
hi everybody
im a newbie in python, i have a question
how do u parse a bunch of text files in a directory?
directory: /dir
files: H20080101.txt ,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |