[kwlug disc.] bash script basics

John Van Ostrand john at netdirect.ca
Fri Feb 9 19:46:59 EST 2007


On Fri, 2007-02-09 at 19:19 -0500, Richard Weait wrote: 

> I'm looking for a bash script solution for what must be a common
> situation.  But I don't have the script-fu to solve this.  And my
> google-fu has failed me, too.
> 
> A CLI tool accepts three arguments.  I'd like to feed the CLI tool
> with a series of these coordinates.  And I'd like to have comments in
> the file that are ignored rather than sent to the CLI.  Surely this is
> a 5 or 6 line script. No?
> 
> How do I feed the lines of arguments to my command?
> 
> I suppose perl could do this in four punctuation symbols.
> 
> 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


#!/bin/bash

while read one two three junk
do
    case "$one" in
    '#'|'')
        # Do nothing
        ;;
    *)
        # Run your command
        echo one: $one
        echo two: $two
        echo three: $three
    esac
done

---End of file--

Then run your command like this:

    mycommand.sh < datafile.txt

--
John Van Ostrand
         Net Direct Inc.
 
CTO, co-CEO
564 Weber St. N. Unit 12
   Waterloo, ON N2L 5C6 
 map 
john at netdirect.ca
        Ph: 519-883-1172
 ext.5102
Linux Solutions / IBM
Hardware
        Fx: 519-883-8533



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.ccjclearline.com/pipermail/kwlug-disc/attachments/20070209/4fc39460/attachment.htm


More information about the KWLUG-Disc mailing list