Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Dec 1995 17:25:41 +0100
From:      Paul Girgensohn <>
Cc:        questions@FreeBSD.ORG
Subject:   Re: Hopefully a simple question
Message-ID:  <>
In-Reply-To: Your message of "Fri, 1 Dec 1995 15:52:15 +0000 ()"
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
>>>>> "JB" == Jeff Brand <> writes:

 JB> In an sh script that I'm trying to program, I would like to read a line 
 JB> from a text file, get the first 'phrase' in a line (via awk) into an if 
 JB> statment. If the if statement passes, I would like to redirect the 3rd 
 JB> word of that line to another command (either an echo, or to execute as 
 JB> its own command..)

 JB> Is there a way to do this? If this will help, the separator is ::
 JB> I have previously catted the file, and used head and tail to look through 
 JB> the file, but I was hoping I could find a more efficient method.

try perl:

while(<>) {
	@line = split(/::/);
	if $line[0] is something {
		do something with $line[2];

just redirect the file to this script
No guarantees!  :)  

 JB> Another possibility: Could I just put the contents of the file (very 
 JB> small, about 5K, probably) into a variable (The file DOES contain 
 JB> newlines.)

Yes. for example:

open (FILE,"filename");
@the_whole_file = <FILE>;
foreach(@the_whole_file) {
	$line = $_; 
	blah blah...

 JB> Thanks for any help that you can give.

 JB> --
 JB> -And remember, you are unique... Just like everybody else.
 JB> -<"Jeff Brand">
 JB> ----------------------------------------------------------

Want to link to this message? Use this URL: <>