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
Assign Values to variables from a text file sarsani Shell Programming and Scripting 3 06-26-2009 08:05 PM
Awk/shell question: Read from file and assign to variables. akbar Shell Programming and Scripting 3 05-07-2008 07:10 PM
How to Read a config file and Assign to Variable redlotus72 UNIX for Dummies Questions & Answers 1 11-13-2006 12:14 PM
Assign value to a variable in a parameter file gopskrish Shell Programming and Scripting 2 06-22-2005 08:26 AM
How can I read variable values from file? redlotus72 UNIX for Dummies Questions & Answers 1 03-14-2005 05:38 AM

Reply
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
  #1 (permalink)  
Old 09-28-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
Read the csv file and assign the values in to variable

I have a csv file with the values seperated by commas.I want to extract these values one by one and assign to a variable using shell script.Any ideas or code?
  #2 (permalink)  
Old 09-28-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
You need to post a sample from your file. 2-3 lines will do.

I would tell you to directly read the fields into variables by changing the IFS variable, but it would be better if you could give a sample.
  #3 (permalink)  
Old 09-28-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
sample file name:sitenames.csv
www.real.com,324kb,1,MyPlace
www.yahoo.com.423kb,2,Mysite,Public site


Datas will be in this form
  #4 (permalink)  
Old 09-28-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Not able to open the sample file
  #5 (permalink)  
Old 09-28-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
i have just put the content of the sample file which is seperated by commas.Not attached any file..
  #6 (permalink)  
Old 09-28-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
assuming sitenames.csv

Code:
www.real.com,324kb,1,MyPlace
www.yahoo.com,423kb,2,Mysite,Public site


Code:
#!/bin/ksh

while IFS=, read site space number name
do
  echo "site      -> [${site}]"
  echo "space   -> [${space}]"
  echo "number -> [${number}]"
  echo "name     -> [${name}]"
done < sitenames.csv

  #7 (permalink)  
Old 02-04-2009
Mikey Mikey is offline
Registered User
  
 

Join Date: Dec 2008
Location: Spotsylvania, Va
Posts: 9
I noticed you used ksh should this work in a bash
Reply

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 12:00 PM.


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