473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to parse files ...

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
Sep 5 '09 #1
4 1917
eWish
971 Expert 512MB
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
Sep 5 '09 #2
KevinADC
4,059 Expert 2GB
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.
Sep 5 '09 #3
Sorry, but simplest solution is:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $file = 'text.txt';
  5. open FILE, $file or die "can't open $file";
  6. my @text = <FILE>;
  7. close FILE;
  8.  
  9. my ( @ids ) = ( join '', @text ) =~ /hop (\d+)[^\d]+?9227493/g;
  10. printf "%s\n", ( join "\n", @ids );
  11.  
where text.txt contains user data
Sep 14 '09 #4
numberwhun
3,509 Expert Mod 2GB
@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
Sep 14 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
22
by: Illya Havsiyevych | last post by:
Hello How easily parse VB/VBA code by VB/VBA code ? Is any ready solutions ? Thank's, illya
19
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...
21
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;...
7
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>...
14
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...
5
AdrianH
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...
1
AdrianH
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...
1
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...
1
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 ,...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.