473,775 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change $/

6 New Member
I have a datafile with the following format from which I need to extract parts of the text and copy to a seperate file :

[HTML]
Header (line 1)
---------------------------
(line 2starts)
Content - Content
Content - Content
Content - Content

Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -
(line break)
Subheader
Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Co
(linebreak)
Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content -
( line2 ends)
----------------
Header (line 3)
-----------------
(line 4 starts)
Content - Content
Content - Content
Content - Content

Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -
(line break)
Subheader
Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Co
(linebreak)
Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content
(line 4 ends)
[/HTML]


The file contains text that repeats the above pattern many times (is often very large).

I would like to change the record seperator so that it reads in the header as on line and the rest of the record as another line. --- isnt part of the file - just a visual cue I put in to demonstrate different lines. Is this possible?
Jun 21 '07 #1
1 1557
miller
1,089 Recognized Expert Top Contributor
Dealing with the record separater is a rather advanced method for parsing a file. I suggest that you first attempt to parse the file using regular techniques. This will often demonstrate if it is even possible to do what you're wanting.

Also please note that your terminology is confusing. Instead of "line 1", I believe you mean record 1. As each of the main content sections contain "lines".

Expand|Select|Wrap|Line Numbers
  1. for (my $line = <DATA>; ! eof(DATA);) {
  2.     my $header = $line;
  3.  
  4.     my $content = '';
  5.     while (defined($line = <DATA>)) {
  6.         last if $line =~ /^Header/;
  7.         $content .= $line;
  8.     }
  9.  
  10.     print $header;
  11.     print "Content = " . length($content) . " characters\n";
  12. }
  13.  
  14. __DATA__
  15. Header (section 1)
  16. Content - Content
  17. Content - Content
  18. Content - Content
  19. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -
  20. Subheader
  21. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Co
  22. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content -
  23. Header (section 2)
  24. Content - Content
  25. Content - Content
  26. Content - Content
  27. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -
  28. Subheader
  29. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Co
  30. Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content -Content - Content
  31.  
Output
Expand|Select|Wrap|Line Numbers
  1. >perl scratch.pl
  2. Header (section 1)
  3. Content = 515 characters
  4. Header (section 2)
  5. Content = 523 characters
  6.  
- Miller
Attached Files
File Type: txt scratch.txt (1.3 KB, 469 views)
Jun 21 '07 #2

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

Similar topics

4
3890
by: J.C. Flores | last post by:
Hello all, First of all, I must state that I'm new to SQL Server, but have been a long-time software guy for quite some time. Please excuse the potential simplicity of the solution to my problem. I create a blank database (TestDB) under my server machine (SQL Server 2000 Standard)... I then create a new table (Run_Number) with only one record in it.
1
3220
by: Spike | last post by:
Hello! Im going to make a javascript for changing alot of images. But im not sure how to do it., where to start.. Ok, first.. this is the isue. I have 3 images(I call them 1a-3a). when u click on image 1a u change" image x" to image 1a when u click on image 2a u change" image x" to image 2a when u click on image 3a u change" image x" to image 3a
0
1830
by: beanweed | last post by:
BACKGROUND ---------- I have an ASP.NET application having two panels. In one panel, an XML document, transformed using xsl, is displayed. In the other panel are some controls that allow a user to change the xml. For example, each "l_item" element appears as a row in a table labelled with a "label"; so if I have <l_item id="1"> <label>blah</label> ...
5
7123
by: Hank | last post by:
My Access 2000 code has been running for several years in our main plant. Now we need to install it, as a stand-along application, at remote sites, some of which are out of state. My problem is the printer destination for special reports such as stickers and mailing labels. The Mailing Label report is, of course, designed here for a specific printer (Mailing Label). At another site, the name could be completely different. Other than...
10
9890
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
4
4455
by: active | last post by:
It appears to me that if I change the Control's client size the controls size does not change to agree with the new size. Does it work like the VB6 ScaleWidth and ScaleHeight? That is after I change the Clientsize does the display stay the same but the number of units required to reference a given point changes? Anyway, it appears to me that If I want to change to size of the control so that the client size is some value, I need to...
3
5016
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change data in the text boxes. Then an "update" button saves the data back to the database. What is the best way to change several properties on most of the textbox controls on the form when the "modify" button is clicked? (e.g. make them editible (and...
2
4503
by: J | last post by:
Hello. I apologize if this isn't the appropriate group for this question but I was wondering if it's possible to allow regular windows domain users to change their passwords through an .asp page? I'm trying to figure out the best way to handle domain users to log into an .asp application tied with SQL Server 2000 on the back end since I keep reading that windows authentication is better practice to log into SQL Server. Thanks in...
11
7458
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
1
16456
by: monkey1001 | last post by:
my program is suppose to show my due change and i got it working but my change and coins are wrong how can i improve it thank you..(its supposed to be in java)
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10107
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6718
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.