[NTLUG:Discuss] A quick script anyone?

Eric Waguespack ewaguespack at gmail.com
Thu Jul 31 11:29:04 CDT 2008


On Thu, Jul 31, 2008 at 10:37 AM, Daniel Hauck <daniel at yacg.com> wrote:

> I know there are several very clever script writers here.  You guys even
> seem to "think" in terms of scripting.  I'm learning little by little
> all the great techniques you guys have shared in the past, but here's
> the present challenge:


I actually think in wingdings

>
>
> Parsing a CSV file and generating some output.
>
> I have a list where the first field is a number and the next two are
> text fields.  A line would look like this:
>
> 10, "US", "United States of America"
>
> I just need to be able to parse this line to fill some variables.  The
> output part I have down pretty well and will be able to transform this
> file (once I get the line parsing part down) into the output desired.
>
> It might be helpful to know that I will need to discard the quote
> characters and just need the text within.
>
>
is this anything like what you had in mind?

$ cat test
10, "US", "United States of America"
11, "LV", "Latveria"

$ IFS="$IFS,"; while read line; do eval set -- $line; echo "the $2, ($3) is
ranked number $1 in worldwide consumption of HFCS"; done < test

the US, (United States of America) is ranked number 10 in worldwide
consumption of HFCS
the LV, (Latveria) is ranked number 11 in worldwide consumption of HFCS

Eric


More information about the Discuss mailing list