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 > 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
Arrays & File Reading Asylus Shell Programming and Scripting 1 12-17-2007 09:15 PM
Help reading an input file in KSH zilla30066 Shell Programming and Scripting 2 02-01-2007 06:45 AM
Using loop reading a file,retrieving data from data base. Sonu4lov Shell Programming and Scripting 1 01-19-2007 03:38 AM
Script for reading an input file gzs553 Shell Programming and Scripting 1 10-17-2006 06:55 AM
Reading Input from File and Duplicates Output noelcantona Shell Programming and Scripting 6 10-18-2005 04:59 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-05-2005
sidamin810 sidamin810 is offline
Registered User
  
 

Join Date: Jun 2005
Location: Mississauga
Posts: 12
Reading in data sets into arrays from an input file.

Hye all,

I would like some help with reading in a file in which the data is seperated by commas. for instance:

input.dat:
1,2,34,/test

for the above case, the fn. will store the values into an array -> data[] as follows:

data[0] = 1
data[1] = 2
data[2] = 34
data[3] = /test

I am trying to write this fn. but dont know how to look for a comma so that the next data can be read in. Any help will be appreciated. Thanks in advance.
  #2 (permalink)  
Old 07-05-2005
sssow sssow is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 179
use perl split
  #3 (permalink)  
Old 07-05-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
What language are you writing the script in?
  #4 (permalink)  
Old 07-05-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
#!/bin/ksh

file='/tmp/sid.txt'
typeset -i i=0

while read input
do
  IFS=,; set -A arr ${input}
  while (( i < ${#arr[@]} ))
  do
    echo "arr[$i]=${arr[$i]}"
    ((i+=1))
  done
  ((i=0))
done < "${file}"
  #5 (permalink)  
Old 07-05-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
ksh
Code:
oldIFS=$IFS
IFS=,
set -A data $(<input.dat)
IFS=$oldIFS
  #6 (permalink)  
Old 07-06-2005
sidamin810 sidamin810 is offline
Registered User
  
 

Join Date: Jun 2005
Location: Mississauga
Posts: 12
script in ksh.

Thanks for the input..!

I am sorry I didn't mention this earlier, but I am using ksh. I am going to try this out with what I am working on.

Once again, thanks a lot for all the input. Goodday!
Sponsored Links
Closed Thread

Bookmarks

Tags
delimited, parsing, perl split

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 04:28 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