The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combining information from a comma delimited file vzismann UNIX for Dummies Questions & Answers 1 08-06-2007 06:20 PM
Parsing comma delimited text file chengwei Shell Programming and Scripting 5 02-23-2007 05:38 AM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 AM
Comma Delimited file dbrundrett Shell Programming and Scripting 2 04-05-2004 10:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-26-2006
grandtheftander grandtheftander is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 8
Loading a comma Delimited file into an Array

Hello,
I have been stuck on this aspect of loading a comma delimited file into an array. I thought i had the syntax right, but my commands are not working the way I want them to. Basically my cut command is splitting the file up by spaces and commas. I want the cut command to ignore white spaces. I have googled, used the man pages, and tried other solutions ie (awk, sed), but I am still stuck on this aspect.

comma delimited file:
Code:
23232321223,11100,N/A,Hey You There,N/A,N/A,Wed Jul 26 09:02:26 2006
Code:
#script to split it into an array
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f2`)
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f3`)
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f4`)
len=${#SPArray[*]}

#Displaying the contents of the array
i=0
while [ $i -lt $len ]; do
 echo "$i: ${SPArray[$i]}"
i=$((i+1))
done
Actual output:
0: 11100
1: N/A
2: Hey
3: You
4: There
the output I wish i had:
0: 11100
1: N/A
2: Hey You There
  #2 (permalink)  
Old 07-26-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Here's an alternative way of doing this that I use (ksh):
Code:
{
x='23232321223,11100,N/A,Hey You There,N/A,N/A,Wed Jul 26 09:02:26 2006'
typeset IFS=,
set -A SParray $( print "${x}" )
set | grep SParray
}
SParray[0]=23232321223
SParray[1]=11100
SParray[2]=N/A
SParray[3]='Hey You There'
SParray[4]=N/A
SParray[5]=N/A
SParray[6]='Wed Jul 26 09:02:26 2006'
  #3 (permalink)  
Old 07-26-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
More could be said. If you only want certain elements as is indicated by your cut -f2,-f3, and -f4, you can reassign them to another array or simply reference them only SParray[1], SParray[2], SParray[3].

Last edited by tmarikle; 07-26-2006 at 07:17 PM.. Reason: sp
Sponsored Links
Closed Thread

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 07:32 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