From owner-freebsd-questions Wed Dec 6 08:25:51 1995 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id IAA27107 for questions-outgoing; Wed, 6 Dec 1995 08:25:51 -0800 (PST) Received: from elixir.e.kth.se (elixir.e.kth.se [130.237.48.5]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id IAA27097 for ; Wed, 6 Dec 1995 08:25:45 -0800 (PST) Received: from zafir.e.kth.se (zafir.e.kth.se [130.237.48.6]) by elixir.e.kth.se (8.6.8.1/8.6.6) with ESMTP id RAA28521; Wed, 6 Dec 1995 17:25:42 +0100 Received: (girgen@localhost) by zafir.e.kth.se (8.6.8.1/8.6.6) id RAA28964; Wed, 6 Dec 1995 17:25:42 +0100 Message-Id: <199512061625.RAA28964@zafir.e.kth.se> To: glitch@mail.bw.lgca.ohio.gov Cc: questions@FreeBSD.ORG Subject: Re: Hopefully a simple question In-Reply-To: Your message of "Fri, 1 Dec 1995 15:52:15 +0000 ()" References: X-Mailer: Mew beta version 0.96 on Emacs 19.29.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Date: Wed, 06 Dec 1995 17:25:41 +0100 From: Paul Girgensohn Sender: owner-questions@FreeBSD.ORG Precedence: bulk >>>>> "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: #!/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 = ; 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> ----------------------------------------------------------