![]() |
Read specific lines from a text file
Hi,
I wrote this script to read each line of a text file and than do something with the line content: Code:
for i in 'cat text.txt'For example I have 10 lines and I want to read only line 3 line 5 line 9 Thanks in advance for help :) |
head -n <file> | tail -1 :-(
|
Quote:
I don't know the exact number of lines in the text file, and I have to read lines jumping some of them. To be clear I need to do something like this: start to read the third line of the file |
You'll find information about reading text lines in the advanced bash scripting guide
It is something like this: Code:
while read linejlinkels |
Quote:
|
this should get you started:
Code:
sed -n 5p file.txt |
Code:
perl -ne 'print if grep {$. == $_ } (3, 5, 9)' text.txt |
Yes, I understood. There are a zillion ways to do that. One of them could be:
Code:
lines_to_skip=0If you want to skip line without actually reading them, that is not possible in the loop AFAIK. You could use an external program for that, but is that really worth doing? jlinkels |
Quote:
I set a variable to the number of line I want to start from Then in the loop I increase this variable to skip one line in sed command Code:
I=3Thanks everybody for help |
| All times are GMT -5. The time now is 11:44 PM. |