The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0