Bash: read a text file line by line.
bash 3.1.17(2)
Hi: I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file? Thanks. |
Hi,
Have a look at this: Code:
#!/bin/bash Code:
$ cat infile Hope this helps. |
It certainly does. I now have the skeleton of my program. This can seem as a easy attitude on my part, but I can assure you I learn from it. Because I'm about to ask one more question.
I have now the line in my power. It is in ONELINE. The line will be of the form <blank space>INDEX NN mm:ss.ss How could I capture the part mm:ss.ss? I want to do this in a shell script language, because I'm learning bash scripting and this would further my knowledge. Regards. |
Hi,
You can use more then one variable after the while read statement: Code:
#!/bin/bash |
How stupid. The read syntax ends [name ...]. Thanks a thousand times.
|
You're welcome :)
|
Note that you can also pipe the output of a command into a loop:
Code:
command | while read Code:
while read |
[QUOTE=druuna;4407869]Hi,
You can use more then one variable after the while read statement: Code:
#!/bin/bash |
All times are GMT -5. The time now is 06:49 PM. |