Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Loading a comma Delimited file into an Array Post 302081607 by grandtheftander on Wednesday 26th of July 2006 12:51:11 PM
Old 07-26-2006
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comma Delimited file

I have a comma delimited file that sometimes has addresses details in. The problem is that the address detail can be seen as: "Sample House, Sample Road". When I run a script specifying the file is comma delimited I would like it to ignore comma's that are in between speech marks. Is this... (2 Replies)
Discussion started by: dbrundrett
2 Replies

2. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

3. UNIX for Dummies Questions & Answers

Combining information from a comma delimited file

I have a comma delimited file which also contains commas in the text. I was wondering how I can combine one whole column of that file with another file. In essence I'm trying to do an excel vlookup in UNIX to return the information from one column in the comma delimited file(containing text commas... (1 Reply)
Discussion started by: vzismann
1 Replies

4. Shell Programming and Scripting

Reading a pipe delimited file and loading teradata

Hi, I am new to UNIX shell scripting (KSH). I have a file in UNIX server which is delimited by |. I require the basic syntax to: read the file move it to a local variables load a database - Teradata Continue until end of file. Note: if the field is have no value inbetween two... (6 Replies)
Discussion started by: shivacbz
6 Replies

5. UNIX for Dummies Questions & Answers

Comma delimited file

Hi All, I have output of sql saved in comma separated file. Now i need to read line by line this file and assign word to a unix variable for further processing Eg: Test file world, 1, 3, 4 earth,2,3,4,5 moon,1,2,3,4 Output should be word1= world word2=1 echo " first word... (7 Replies)
Discussion started by: gwrm
7 Replies

6. UNIX for Dummies Questions & Answers

Flat File - Comma Delimited

I have a flat file whose contents are comma delimited and there are 84 columns in total, so everytime I try to view the contents, things get over lapped it becomes diffcult to read through the result set. Is there a command / what would be the best way...if I want to view the results alligned... (4 Replies)
Discussion started by: priya33184
4 Replies

7. Shell Programming and Scripting

Comma delimited file manipulation

Question about how to change the first & last name in column one & two so that the names have a capital letter for just the first letter. Example: asdf@asdf.com,asdf,asdfasdf,176.23.22.345,4/12/2012 changed to: asdf@asdf.com,Asdf,Asdfasdf,176.23.22.345,4/12/2012 Thank you kindly, Nick (2 Replies)
Discussion started by: nickytcom
2 Replies

8. Shell Programming and Scripting

Need a script to convert comma delimited files to semi colon delimited

Hi All, I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
Discussion started by: CarpKing
4 Replies

9. Shell Programming and Scripting

How to extract field delimited by comma and store into an array?

hi, i have a variable which contains some file names separated by comma. example FNAME="abc.txt,def.txt,ghi.txt" i want to extract each filename and store it into an array and also count the number of files in the array. file=abc.txt file=def.txt file=ghi.txt i thought of using the... (8 Replies)
Discussion started by: Little
8 Replies

10. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies
TAP::Parser::Iterator::Array(3pm)			 Perl Programmers Reference Guide			 TAP::Parser::Iterator::Array(3pm)

NAME
TAP::Parser::Iterator::Array - Internal TAP::Parser array Iterator VERSION
Version 3.17 SYNOPSIS
# see TAP::Parser::IteratorFactory for preferred usage # to use directly: use TAP::Parser::Iterator::Array; my @data = ('foo', 'bar', baz'); my $it = TAP::Parser::Iterator::Array->new(@data); my $line = $it->next; DESCRIPTION
This is a simple iterator wrapper for arrays of scalar content, used by TAP::Parser. Unless you're subclassing, you probably won't need to use this module directly. METHODS
Class Methods "new" Create an iterator. Takes one argument: an $array_ref Instance Methods "next" Iterate through it, of course. "next_raw" Iterate raw input without applying any fixes for quirky input syntax. "wait" Get the wait status for this iterator. For an array iterator this will always be zero. "exit" Get the exit status for this iterator. For an array iterator this will always be zero. ATTRIBUTION
Originally ripped off from Test::Harness. SEE ALSO
TAP::Object, TAP::Parser, TAP::Parser::Iterator, TAP::Parser::IteratorFactory, perl v5.12.1 2010-04-26 TAP::Parser::Iterator::Array(3pm)
All times are GMT -4. The time now is 03:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy