Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Hello! I want to read text from a file (the file is just a normal paragraph) word by word. To be honest I have no clue how to do this. I can't use input redirection, I need to read from a file given by parameter 1.
Here's the summary of the problem: I need to read from a file ($1) word by word (after which I apply a test to each word but I think I can do that). How can I do this? Can I use the read statement?
I can't use input redirection because this is an assignment for a class. The program can only be invoked by the program name and its argument. This is a bash script with the text file in the same directory as the script, on a Ubuntu system.
If I can't figure anything else out I'll use input redirection but I will lose points for doing so.
If you can't use redirections*, have a look at file descriptors.
To work word-by-word, try using an array.
(hint: take a look at read's options)
*I get the sense that this rule only applies to launching the script itself, but it would be very strange indeed if it also referred the commands inside the script. You might want to get clarification on that.
When I want to read a file a word at a time I use for to iterate over the output of cat. Don't know if that's the most efficient way to do it, but it works and it's very simple.
Since you say it's an assignment and I've already found some alternatives to my usual method in less than 60 seconds via Google (all of which are a lot more complicated than mine and I'm not seeing how they're technically better), I'm a bit reluctant to give you actual code but if you look at the for and cat commands and also command substitution it should be easy to figure out.