[K12OSN] Scripting help...how to read lines from a text file
Les Mikesell
les at futuresource.com
Tue Oct 4 17:24:10 UTC 2005
On Tue, 2005-10-04 at 11:57, Roger wrote:
> On 10/4/05, David Trask <dtrask at vcsvikings.org> wrote:
> > I understad 90%....one question...where do I indicate the filename?
> > Here's what I believe it will look like, but I'm not totally sure where I
> > indicate the path to the text file....
> >
> > #!/bin/bash
> > cat $1 |while read LINE
> > do
> > echo "Processing $LINE"
> > stop $LINE
> > done
>
> It's given in the command line:
>
> scriptname filename
>
> Or, instead of $1, you could sub the file name.
>
> as in
> cat filename |
A couple of notes: parameters from the command line are available
in a script by their positional number: i.e. $1 is the first, $2
the second, etc. or you can 'shift' your way through a larger
number. Also, 'read' can accept multiple variables, split
by the current $IFS variable (default is white space). If there
are more values than variables, the last one gets the rest of
the line.
--
Les Mikesell
les at futuresource.com
More information about the K12OSN
mailing list