Results 1 to 4 of 4
I have been playing around with a script for a few hours and now I need to be able to output the lines in a text file one by one ...
- 12-09-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 1
How to read a line from a txt file in a script?
I have been playing around with a script for a few hours and now I need to be able to output the lines in a text file one by one to be used later in the script.
What it gonna do is to read a log file and grep the usernames, then write them to a file, and then run one script for each user, to search for more information about them in the log.
But I don't know how to output a single line from a file, and google does not return any solution.
Thanks
- 12-09-2010 #2
- 12-10-2010 #3
Another option, if you need to break out this loop for some reason, would be to open the file:
You can use that "read" command in a while loop as in barriehie's examples.Code:exec 5<$FILENAME # That's basic redirection syntax: $FILENAME is opened for reading and bound to file descriptor 5. "exec" is a shell built-in which applies this redirection to the shell's session. #To read a line from the open file, just redirect the input of "read" to FD #5... read x <&5 #To close the file, there's the following syntax. You can think of it as "redirect 5 from nothing"... exec 5<&-
- 12-11-2010 #4
Here's a link to a BASH scripting guide. I've found it to be indispensable.
Advanced Bash Scripting Guide Download - Softpedia


Reply With Quote
