Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Dec 1995 17:25:41 +0100
From:      Paul Girgensohn <girgen@elixir.e.kth.se>
To:        glitch@mail.bw.lgca.ohio.gov
Cc:        questions@FreeBSD.ORG
Subject:   Re: Hopefully a simple question
Message-ID:  <199512061625.RAA28964@zafir.e.kth.se>
In-Reply-To: Your message of "Fri, 1 Dec 1995 15:52:15 +0000 ()"
References:  <Pine.NEB.3.91.951201154747.3394A-100000@mail.bw.lgca.ohio.gov>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
>>>>> "JB" == Jeff Brand <glitch@mail.bw.lgca.ohio.gov> 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:

#!/usr/bin/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:

#!/usr/bin/perl
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" glitch@mail.bw.lgca.ohio.gov>
 JB> ----------------------------------------------------------




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?199512061625.RAA28964>