[NTLUG:Discuss] A quick script anyone?
Eric Schnoebelen
eric at cirr.com
Thu Jul 31 13:24:31 CDT 2008
Daniel Hauck writes:
- Eric Schnoebelen さんは書きました:
- > Daniel Hauck writes:
- > - Parsing a CSV file and generating some output.
- >
- > Here's a start for you.. You're still going to have quotes
- > around the strings, but that may be useful for later evaluation
- > of the strings.
- >
- > #!/bin/sh
- > #
- > OIFS="${IFS}"
- > IFS="${IFS},"
- > while read num short long; do
- > echo ${num}:${short}:${long}
- > done
- > IFS="${OIFS}"
-
- That's just about perfect. I just need a way to get rid of the quotes.
try the following instead.. (using eval and set, as someone else pointed
out..)
#!/bin/sh
#
OIFS="${IFS}"
IFS="${IFS},"
while read ln; do
eval set -- $ln
echo "$1:$2:$3"
done
IFS="${OIFS}"
$1 will have the first field, $2 will have the second, $3, the
third.. no quotes, but you'll need to remember to quote the
variable as you pass them around and manipulate them.
--
Eric Schnoebelen eric at cirr.com http://www.cirr.com
Real programmers have trouble suppressing homicidal
tendencies when asked, "Are you sure?"
More information about the Discuss
mailing list