![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to use array values after the loop. | Devesh5683 | Shell Programming and Scripting | 1 | 05-13-2008 08:38 PM |
| Loading a comma Delimited file into an Array | grandtheftander | UNIX for Dummies Questions & Answers | 2 | 07-26-2006 02:19 PM |
| Comma Seperated List of Values | brap45 | Shell Programming and Scripting | 9 | 02-23-2006 05:12 AM |
| How to load comma seperated values file (*.csv) into Oracle table | handynas | UNIX for Advanced & Expert Users | 4 | 06-24-2002 01:35 PM |
| How to load comma seperated values file (*.csv) into Oracle table | handynas | UNIX for Dummies Questions & Answers | 5 | 06-05-2002 12:10 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Splitting comma separated values into an array
I'm attempting to create a KSH array out of a string like this: ",,,value1,value2,," I have created the array but I only get two elements, one for value1 and one for value2. I have ended up with something like this but I don't like it: Code:
set -A JUNK
xx=0
for i in $(print ",,,value1,value2,," | nawk '{gsub(/,/," \n",$0);print}')
do
print ".$i."
JUNK[xx]=$i
(( xx += 1 ))
done
for i in "${JUNK[@]}"
do
print ".$i."
done
The results: Code:
. . . . . . .value1 . .value2 . . . . . If i leave out the space character before the newline in this gsub command: Code:
gsub(/,/," \n",$0); ...I get this output: Code:
.value1 . .value2 . I really don't want the spaces at the end of each string and I nead an array of every CSV field (even the empty values). I have tried several approaches including changing IFS and looping through the fields but this doesn't seem to work at all. What am I missing here? Thomas |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|