473,387 Members | 1,486 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,387 software developers and data experts.

finding text in perl

fetaelin
Hi..
I have a textfile like this...

*****************************
blablalba
*****
begin
somve value 3 5 XXX
blablabla
**
bla
somve value 4 6 WWW
end
****************************
*****************************
blablalba
*****
begin
somve value 3 5 XXX
blablabla
**
bla
somve value 4 6 YYY
end
****************************
*****************************
blablalba
*****
begin
somve value 3 5 XXX
blablabla
**
bla
somve value 4 6 ZZZ
end
****************************
I want to print out from begin to end ONLY that part who ase YYY
so the first part which have somve value 4 6 WWW souledent come out
the result of the script sould be printing

begin
somve value 3 5 XXX
blablabla
**
bla
somve value 4 6 YYY
end



how can I do that ?
the text is in a file calles myfile.txt
May 9 '07 #1
6 1622
KevinADC
4,059 Expert 2GB
post the perl code you have written so far.

Read the second and third FAQ on this page:

http://perldoc.perl.org/perlfaq6.html

I'm having trouble matching over more than one line. What's wrong?

How can I pull out lines between two patterns that are themselves on different lines?
May 9 '07 #2
post the perl code you have written so far.

Read the second and third FAQ on this page:

http://perldoc.perl.org/perlfaq6.html

I'm having trouble matching over more than one line. What's wrong?

How can I pull out lines between two patterns that are themselves on different lines?

okay..
I can use the
perl -0777 -ne 'print "$1\n" while /START(.*?)END/gs' file1
BUT I want a condition too, if there is a word "XXXXX" between start and end, then it should print it else dont print
how to write the conditon ?
May 10 '07 #3
KevinADC
4,059 Expert 2GB
maybe:

Expand|Select|Wrap|Line Numbers
  1. perl -0777 -ne 'print "$1\n" while /START(.*?XXXXX.*?)END/gs' file1
May 10 '07 #4
maybe:

Expand|Select|Wrap|Line Numbers
  1. perl -0777 -ne 'print "$1\n" while /START(.*?XXXXX.*?)END/gs' file1

okay.. that worked, but The sart and the end did not exist in the answer,
how can I do the same thing but having start and the end with the text ?
May 15 '07 #5
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. perl -0777 -ne 'print "START$1END\n" while /START(.*?XXXXX.*?)END/gs' file1
May 15 '07 #6
miller
1,089 Expert 1GB
As a script:

Expand|Select|Wrap|Line Numbers
  1. @ARGV = 'myfile.txt';
  2.  
  3. while (<>) {
  4.     if (/^begin$/../^end$/) {
  5.         $t .= $_;
  6.     } else {
  7.         print "$t" if $t =~ /YYY/;
  8.         $t = '';
  9.     }
  10. }
  11.  
May 15 '07 #7

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

Similar topics

0
by: Noah | last post by:
I inherited a large perl project with many small perl files spread out over different directories. The project is an admin tool with a cgi interface. I suspect that many of the files are no longer...
9
by: Paweł | last post by:
Hello! I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild" characters like '?' for any one char and...
4
by: Larry | last post by:
I have a Perl script using DBD::DB2, that runs during system startup on a Solaris system. The script is working fine during startup on many machines, except on one machine it fails complaining...
12
by: bg_ie | last post by:
Hi, I'm updating my program to Python 2.5, but I keep running into encoding problems. I have no ecodings defined at the start of any of my scripts. What I'd like to do is scan a directory and...
1
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
9
by: richee | last post by:
Hi all, I am new to Perl but see that it offers some fantastic opportunities and am trying to use it more in problem solving but could do with a little help on a problem thats driving me nuts.......
12
by: Jeff | last post by:
As I'm learning PHP, I'm making a fair number of mistakes in syntax. In perl, you can turn on reading these errors from the browser by adding this: use CGI::Carp 'fatalsToBrowser'; Is there...
5
by: Sengly | last post by:
Dear all, This might be off group but I am looking for a python library that can help me to find a sense of a word in a text and eventually a list of synonyms of that term. I searched the web...
2
by: sbettadpur | last post by:
hello, I am trying to install the Text::NLP::Stanford::EntityExtract perl module on windows xp. But its not installing properly... can anybody tell solution for the above problem. But its...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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,...

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.