E
EmJayEm
I have a text file with contents:
ENTRY= entry 1
here goes the contents for entry 1
here goes the contents for entry 1
here goes the contents for entry 1
ENTRY= entry 2
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
ENTRY= entry 3
here goes the contents for entry 3
here goes the contents for entry 3
here goes the contents for entry 2
In the text file, entry 1 is on line 1, entry 2 is on line 5, entry 3 is on
line 9.
I wish to display just one entry. eg. entry 2, like so:
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
I've done it like this:
# get the entry's line number in the text file
while (! file[$line_of_file]=~m/ENTRY=(.*)/) # for each line of the entry
until the next entry.
{
print file[$line_of_file]; # print the line of the entry
}
For printing entry 3 the condition in the while loop has to test the end of
the file, like so:
while ("$line_of_file" eq "$total_number_of_lines_in_file") # while not
end of file
{
print file[$line_of_file]; # print the line of the entry
}
I've tried to combine the two condition statements into one while loop as
below but it didn't work, yet the conditions work separately. Any ideas?
while ((! file[$line_of_file]=~m/ENTRY=(.*)/) || ("$line_of_file" eq
"$total_number_of_lines_in_file"))
ENTRY= entry 1
here goes the contents for entry 1
here goes the contents for entry 1
here goes the contents for entry 1
ENTRY= entry 2
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
ENTRY= entry 3
here goes the contents for entry 3
here goes the contents for entry 3
here goes the contents for entry 2
In the text file, entry 1 is on line 1, entry 2 is on line 5, entry 3 is on
line 9.
I wish to display just one entry. eg. entry 2, like so:
here goes the contents for entry 2
here goes the contents for entry 2
here goes the contents for entry 2
I've done it like this:
# get the entry's line number in the text file
while (! file[$line_of_file]=~m/ENTRY=(.*)/) # for each line of the entry
until the next entry.
{
print file[$line_of_file]; # print the line of the entry
}
For printing entry 3 the condition in the while loop has to test the end of
the file, like so:
while ("$line_of_file" eq "$total_number_of_lines_in_file") # while not
end of file
{
print file[$line_of_file]; # print the line of the entry
}
I've tried to combine the two condition statements into one while loop as
below but it didn't work, yet the conditions work separately. Any ideas?
while ((! file[$line_of_file]=~m/ENTRY=(.*)/) || ("$line_of_file" eq
"$total_number_of_lines_in_file"))