Register
It is currently Thu Sep 18, 2014 3:43 pm

Having problems with file reading (CSV format)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Thu May 29, 2014 11:28 am   

Joined: Thu May 29, 2014 11:12 am
Posts: 2
Hello there to all the bash scripting masters i see we have in this forum!
I am new here, and generally in bash scripting.
I came from windows batch scripting and i am having troubles reading files.

let me explain my problem:

i have a bash script in a dir called "dir1". Under that dir, there is another dir "dir2" and under that one is another called "dir3" wich has a file called "logindata" so the tree is as follows:

dir1 -> script.sh
|_ dir2
|_ dir3 -> logindata

the file logindata contains three values in csv format, so its contents are something like "user1,pass4user1,server.dns.com"

my intention with the script.sh is to read that line from logindata and assign these three values to their vars so i'm trying this:

Code:
username=""
password=""
server=""

IFS=","
while read usrname passwrd srver
do
    username=$usrname
   password=$passwrd
   server=$srver
done < dir2/dir3/logindata


I believe that the problem is the way i reference the file in the "done <" line but i cant find a way to solve it.

If someone can help me i would appreciate it so much.
Thank you in advance.


Top
 Profile  
 PostPosted: Fri May 30, 2014 8:04 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 546
hi,

Quote:
I believe that the problem is [...]
but, what are the facts?
I don't see a real problem with the script.


Top
 Profile  
 PostPosted: Fri May 30, 2014 10:04 am   

Joined: Thu May 29, 2014 11:12 am
Posts: 2
hi friend!

the facts are that i never get into the while loop, i put some echoes inside but never get in...

thats why i though the problem was the way i write the path because i swear the "logindata" file is there


Top
 Profile  
 PostPosted: Fri May 30, 2014 12:39 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 546
:-/
Code:
$ mkdir -p dir2/dir3
$ echo "user1,pass4user1,server.dns.com" > dir2/dir3/logindata
$ while IFS=',' read usrname passwrd srver
do
    username=$usrname
   password=$passwrd
   server=$srver
   echo "$username;;$password;;$server"
done <dir2/dir3/logindata
user1;;pass4user1;;server.dns.com


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP