Sudhindra Bhat
May 17 2004, 09:27 AM
Hi
I wanted some help on a piece of code that I was writing. Well the
requirement is like this. I have a file whose looks like this
(1) Test: 123456 ABCDEF
123456
(2) Results: ABCDEF
Now I want my script to output all the contents between the two tags Test
and Results. i.e. 123456 ABCDEF 123456. Can someone help me with this?
Regards,
Sudhindra
John W . Krahn
May 17 2004, 10:25 AM
On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
Hello,
QUOTE |
I wanted some help on a piece of code that I was writing. Well the requirement is like this. I have a file whose looks like this
(1) Test: 123456 ABCDEF
123456
(2) Results: ABCDEF
Now I want my script to output all the contents between the two tags Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with this?
|
while ( <FILE> ) {
if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
print
}
}
John
--
use Perl;
program
fulfillment
Sudhindra Bhat
May 17 2004, 11:11 AM
Hi
Thanks. But there is a small issue. Considering the same example, the piece
of code sent by you prints 123456 which is not on the same line as "Test:"
But it doesn't print the characters 123456 ABCDEF which is on the same line
as "Text:"
Regards,
Sudhindra
-----Original Message-----
From: John W.Krahn [mailto:[Email Removed]]
Sent: Monday, May 17, 2004 4:56 PM
To: Perl Beginners
Subject: Re: Query
On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
Hello,
QUOTE |
I wanted some help on a piece of code that I was writing. Well the requirement is like this. I have a file whose looks like this
(1) Test: 123456 ABCDEF
123456
(2) Results: ABCDEF
Now I want my script to output all the contents between the two tags Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with this?
|
while ( <FILE> ) {
if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
print
}
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Sudhindra Bhat
May 18 2004, 10:40 AM
Hi
This doesn't seem to work. I get a blank output. But yes the output that is
want is
123456 ABCDEF
123456
Regards,
Sudhindra
-----Original Message-----
From: Jose Alves de Castro [mailto:[Email Removed]]
Sent: Tuesday, May 18, 2004 3:55 PM
To: Sudhindra Bhat
Cc: Perl Beginners
Subject: Re: Query
On Tue, 2004-05-18 at 07:36, Sudhindra Bhat wrote:
QUOTE |
Hi
Thanks. But there is a small issue. Considering the same example, the piece of code sent by you prints 123456 which is not on the same line as "Test:" But it doesn't print the characters 123456 ABCDEF which is on the same line as "Test:"
|
That's because it is *not* printing the line with "Test:"... it is only
printing the lines between the one that matches "Test:" and the one that
matches "Results:"
This prevents the line with "Test:" from being printed: !/Test:/
This prevents the line with "Results:" from being printed: !/Results:/
Exactly what output were you expecting?
Something like this, perhaps:
==123456 ABCDEF
123456
(2)
==
Would that be it?
If so, try
while (<FILE>) {
if ( /Test:/ .. /Results:/ ) {
if ( /Test:/ ) { print $' }
elsif ( /Results:/ ) { print $` }
else { print }
}
}
HTH,
jac
QUOTE |
Regards, Sudhindra
-----Original Message----- From: John W.Krahn [mailto:[Email Removed]] Sent: Monday, May 17, 2004 4:56 PM To: Perl Beginners Subject: Re: Query
On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
Hi
Hello,
I wanted some help on a piece of code that I was writing. Well the requirement is like this. I have a file whose looks like this
(1) Test: 123456 ABCDEF
123456
(2) Results: ABCDEF
Now I want my script to output all the contents between the two tags Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with this?
while ( <FILE> ) { if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) { print } }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response -- |
Jos Alves de Castro <[Email Removed]>
Telbit - Tecnologias de Informao
Sudhindra Bhat
May 18 2004, 11:08 AM
Thanks a million. It works perfectly.
Regards,
Sudhindra
-----Original Message-----
From: Jose Alves de Castro [mailto:[Email Removed]]
Sent: Tuesday, May 18, 2004 5:01 PM
To: Sudhindra Bhat
Cc: Perl Beginners
Subject: RE: Query
In that case, with this:
#!/usr/bin/perl -w
use strict;
while (<>) {
if ( /Test:/ .. /Results:/ and !/Results:/ ) {
if ( /Test:s*/ ) {
print $'
}
else {
print if /./
}
}
}
you can get that output ( run the script with the input file).
HTH,
jac
On Tue, 2004-05-18 at 12:28, Sudhindra Bhat wrote:
QUOTE |
Hi
This doesn't seem to work. I get a blank output. But yes the output that is want is
123456 ABCDEF 123456
Regards, Sudhindra
-----Original Message----- From: Jose Alves de Castro [mailto:[Email Removed]] Sent: Tuesday, May 18, 2004 3:55 PM To: Sudhindra Bhat Cc: Perl Beginners Subject: Re: Query
On Tue, 2004-05-18 at 07:36, Sudhindra Bhat wrote: Hi
Thanks. But there is a small issue. Considering the same example, the piece of code sent by you prints 123456 which is not on the same line as "Test:" But it doesn't print the characters 123456 ABCDEF which is on the same line as "Test:"
That's because it is *not* printing the line with "Test:"... it is only printing the lines between the one that matches "Test:" and the one that matches "Results:"
This prevents the line with "Test:" from being printed: !/Test:/
This prevents the line with "Results:" from being printed: !/Results:/
Exactly what output were you expecting? Something like this, perhaps:
==> 123456 ABCDEF
123456
(2) == Would that be it?
If so, try
while (<FILE>) { if ( /Test:/ .. /Results:/ ) { if ( /Test:/ ) { print $' } elsif ( /Results:/ ) { print $` } else { print } } }
HTH,
jac
Regards, Sudhindra
-----Original Message----- From: John W.Krahn [mailto:[Email Removed]] Sent: Monday, May 17, 2004 4:56 PM To: Perl Beginners Subject: Re: Query
On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
Hi
Hello,
I wanted some help on a piece of code that I was writing. Well the requirement is like this. I have a file whose looks like this
(1) Test: 123456 ABCDEF
123456
(2) Results: ABCDEF
Now I want my script to output all the contents between the two tags Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with this?
while ( <FILE> ) { if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) { print } }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response -- Jos Alves de Castro <[Email Removed] Telbit - Tecnologias de Informao -- |
Jos Alves de Castro <[Email Removed]>
Telbit - Tecnologias de Informao
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
John W. Krahn
May 18 2004, 08:06 PM
Sudhindra Bhat wrote:
Hello,
QUOTE |
This doesn't seem to work. I get a blank output. But yes the output that is want is
123456 ABCDEF 123456
|
while ( <FILE> ) {
next unless /S/;
if ( s/^.*?Test:s*// .. /Results:/ and !/Results:/ ) {
print
}
}
John
--
use Perl;
program
fulfillment
Thomas Btzler
Jul 7 2005, 01:51 PM
madhurima das <[Email Removed]> wrote:
QUOTE |
I have the following problem:
|
Looks like the previous time you posted this.
[...]
QUOTE |
my @z = system("assign.f",'$x','$y'); [...] |
Read the perlfunc manpage on system.
1. system does return a scalar.
2. that scalar is not the output of the program
you called.
3. the Fortran code you are calling does not expect
parameters on the command line. It tries to read them
from standard input.
4. you're trying to run Fortran source code. That will
not work.
HTH,
Thomas
PS: No, I will not do your homework for you.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.