[kwlug disc.] bash script basics
Chris Frey
cdfrey at foursquare.net
Fri Feb 9 19:39:00 EST 2007
On Fri, Feb 09, 2007 at 07:19:32PM -0500, Richard Weait wrote:
> The data file might look like this.
>
> #
> # this is a fake data file
> #
>
> 1 2 3 # three whitespace separated numbers
> 4 5 6
> 7 8 9
> 10 11 12 # each number up to 5 or 6 digits
> # comments
> 13 14 15 # real data is arbitrary, not sequential
> 16 17 18
You can prefilter with grep, removing comments and blank lines. Keeping
it simple:
grep -v "^ *#" | grep -v "^$"
Then you can read each line with:
while read A B C D ; do
...
done
This is a shell command, reading space separated input and putting them
in the given environment variables. You want an extra D at the end
to catch any "comments".
Then do a few if statements to make sure A, B, and C are valid,
then run your command:
command $A $B $C
This all assumes the data is coming in on stdin.
- Chris
More information about the KWLUG-Disc
mailing list