Re: [SLUG] Scripting Question

From: Paul M Foster (paulf@quillandmouse.com)
Date: Wed Nov 28 2001 - 01:22:53 EST


On Tue, Nov 27, 2001 at 11:01:51PM -0500, Paul Braman wrote:

>
> On Tue, 27 Nov 2001, Paul M Foster wrote:
>
> > Here's what I've got: I want to be able to peel off one line at a time
> > from a file and process just that line, before going on to the next one.
> > I tried something like:
> >
> > cat myfile | while read ; do
> > do_something $REPLY
> > done
> >
> > but it didn't work. I'm trying to avoid awk, sed, perl and such, and
> > only do this in bash.
> >
> > Any clues?
>
> What you need to do is set your inter-field-seperator to only "newline".
>
> For example, the following script will read a file a line at a time and
> echo it to output.
>
> ===================
> IFS='
> '
> for line in `cat filename`
> do
> echo $line
> done
> exit 0
> ===================
>
> The key to setting IFS is to put a single quote and immediately hit
> <enter> before putting another quote. If you put a space in there you
> will still break on *both* spaces and newlines when reading in "fields".
>

Outstanding! I should have thought of the "for line in `cat filename`"
method. Duh. This works very well.

Paul



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:54:40 EDT