For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > Query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Query
Sujana Setty

2004-05-19, 3:30 am

I am using the below command

awk -F: ' $3 ~/bharghav/ { print $0 } ' data.file

but this command produces both
Vijayb:12345:Vijay B bharghav
vijaya:12347:vijaya bharghavi

what to if I want only record containing exactly the word "bharghav"
that is
Vijayb:12345:Vijay B bharghav


-----Original Message-----
From: John W. Krahn [mailto:krahnj@acm.org]
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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

****************************************
**********************************
This email (including any attachments) is intended for the sole use of the
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
distribution or forwarding of any or all of the contents in this message is
STRICTLY PROHIBITED. If you are not the intended recipient, please contact
the sender by email and delete all copies; your cooperation in this regard
is appreciated.
****************************************
**********************************
Ramprasad A Padmanabhan

2004-05-19, 4:30 am

I think you forgot this is the perl list not the awk list

But anyway in perl I will do something like
perl -ne 'print if(((split(/:/,$_))[2]) =~/\bbhargav\b/)' data.file


Ram


On Wed, 2004-05-19 at 11:29, Sujana_Setty@Satyam.com wrote:
> I am using the below command
>
> awk -F: ' $3 ~/bharghav/ { print $0 } ' data.file
>
> but this command produces both
> Vijayb:12345:Vijay B bharghav
> vijaya:12347:vijaya bharghavi
>
> what to if I want only record containing exactly the word "bharghav"
> that is
> Vijayb:12345:Vijay B bharghav
>
>
> -----Original Message-----
> From: John W. Krahn [mailto:krahnj@acm.org]
> 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,
>
>
>
> while ( <FILE> ) {
> if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
> print
> }
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
> ****************************************
**********************************
> This email (including any attachments) is intended for the sole use of the
> intended recipient/s and may contain material that is CONFIDENTIAL AND
> PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
> distribution or forwarding of any or all of the contents in this message is
> STRICTLY PROHIBITED. If you are not the intended recipient, please contact
> the sender by email and delete all copies; your cooperation in this regard
> is appreciated.
> ****************************************
**********************************


John W. Krahn

2004-05-19, 6:30 pm

Sujana Setty wrote:
>
> I am using the below command
>
> awk -F: ' $3 ~/bharghav/ { print $0 } ' data.file
>
> but this command produces both
> Vijayb:12345:Vijay B bharghav
> vijaya:12347:vijaya bharghavi
>
> what to if I want only record containing exactly the word "bharghav"
> that is
> Vijayb:12345:Vijay B bharghav


perl -F: -ane'$F[2] =~ /\bbharghav\b/ and print' data.file


John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com