how to read values from a file (as part of a script)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
how to read values from a file (as part of a script)
I want to read values from a file...these are basically one word values, that is to say that the text file I want to read from contains lines of word length 1, as in:
word1
word2
word3
etc.
I actually only need the first word of the file and I want to assign it to a variable.
I am not very familiar with UNIX but I have practice with a UNIX-based software, and in this software, the method of sequentially reading values from a text file is the following:
list="list.txt"
while (fscan(list,s1) !=EOF){
print (s1)
}
where:
s1 is string variable
list is a list variable that goes through the text file sequentially
fscan is a task the sets the value of s1 to the current value of list
The above program would read through to the end of file and print the value of each word.
so say if I had a file list.txt with entries:
word1
word2
word3
the output of the above program would be:
word1
word2
word3
My question is, what tasks and variables can be used to get the same result in UNIX?
And also regarding the list variable...how does one declare and assign values to such variables in UNIX?
Thanks to both comments...and no, this isn't a class assignment
like I said I often use a unix based software (an astronomy package) that has a programming language like that shown in my first post, however I needed a unix variable for a tiny part of a script (that I wrote for the astronomy package).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.