Shell Scripting: How to pick lines out of files by line number.
In a shell script (Linux), how would you pick out certain lines from a text file using line numbers. What I want to do is loop through each line of the file seperately. First, I want to read line 1, and perform an operation according to line 1's content, then I want to go to line 2, etc....
All I can find is how to pull lines from a file based on a pattern match (like grep). I want to get every line one at a time no matter what the pattern. Each line only contains one word. Thanks. Louie. |
You could loop as this :
Code:
i=1 |
Here's one way:
Code:
line_number=1 Code:
while read line_word |
There's probably several ways, two would be to
use awk or sed Code:
awk '{if( NR==7)print}' file Code:
sed -n '7p' file Cheers, Tink |
All times are GMT -5. The time now is 01:48 PM. |