How to read contents of a file into variable :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read contents of a file into variable :(
# 1  
Old 03-06-2011
How to read contents of a file into variable :(

My file is in this format :

username : student information : default shell : student ID

Eg :

joeb:Joe Bennett:/bin/csh:1234
jerryd:Jerry Daniels:/bin/csh:2345
deaverm: Deaver Michelle:/bin/bash:4356
joseyg:Josey Guerra:/bin/bash:8767
michaelh:Michael Hall:/bin/ksh:1547

I have to read the contents of each field for creating user accounts.

I have to use each field in my useradd command for creating user accounts.

Later i even have to create password based on username and student id..

All i need is an idea.

am struck at retrieving the values from file. Smilie

Any help would be greatly appreciated .

Thank you .. SmilieSmilieSmilie

---------- Post updated at 04:28 PM ---------- Previous update was at 04:26 PM ----------

Am using Fedora 14 Smilie

---------- Post updated at 04:42 PM ---------- Previous update was at 04:28 PM ----------

can anyone help me Smilie
# 2  
Old 03-06-2011
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

3. Programming

read() contents from a file

Hi, I'm trying to implement a C program on ubuntu which reads the contents of a file that is passed in as an argument and then displays it to the screen. So far I've cobbled together this from bits online but most of it is probably wrong as its all copied and pasted... #include <stdio.h>... (2 Replies)
Discussion started by: cylus99
2 Replies

4. Shell Programming and Scripting

how to read contents of file?

I have made a script something like this. I want it to read the contents of either file or directory but 'cat' and 'ls' is not working. Can anyone help me? I am a newbie in scripting so dont know much about it. I also dont know how can i put my code separatly on this forum #!/bin/bash echo... (9 Replies)
Discussion started by: nishrestha
9 Replies

5. Homework & Coursework Questions

How to read contents of a file into variable :(

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to read the contents of each field of a file creating user accounts. The file will be of format : ... (6 Replies)
Discussion started by: dude_me5
6 Replies

6. Shell Programming and Scripting

Read contents from a file

Hi Friends, I am new to this forum. Just struck up with a logic. I have a csv file seperated by ":" (colons). This csv file contains hostname and groups as follows: HOSTNAME:VT Group SGSGCT2AVPX001:Team1 SGSGCT2AVPX003:Team2 SGSGCT2AVPX005:Team2 PHMNCTTAVPX001:Team3 I want to... (2 Replies)
Discussion started by: dbashyam
2 Replies

7. Shell Programming and Scripting

Read the contents of a file and store them in a variable

Hi Gurus, I am trying for a scenario where in I want to read the contents of a file line by line and then store them in variables. Below is the script: #!/bin/ksh while read line do id=`echo $line | cut -f1 -d |` name=`echo $line | cut -f2 -d |` echo $id ... (11 Replies)
Discussion started by: svajhala
11 Replies

8. Shell Programming and Scripting

how to read the contents of a file using PERL

Hi My requirement is to read the contents of a fixed length file and validate the same. But am not able to read the contents of the file and when i tried it to print i get <blank> as an output... I used the below satatements for printing the contents ... (3 Replies)
Discussion started by: meva
3 Replies

9. Shell Programming and Scripting

read contents of a file with serveral lines & assign it to a variable

Hi All I have a file for ex .log file which contain several lines within it. I have to read that file contents & assing that to a variable. (2 Replies)
Discussion started by: satyam.sumit
2 Replies

10. Shell Programming and Scripting

Read File and use contents to rename another

Hello guys, thank God that I found this forum. I hope that someone can help me because I don't have any idea on how to start it. I know that for some of you this is a very simple task but I'm not as advance on shell scripting like many people out there. I got this file with a permanent... (10 Replies)
Discussion started by: Shark Tek
10 Replies
Login or Register to Ask a Question