Hi.
I've got a code to remove lines from a file "%EarthNav%" with defined keywords. It does not seem to work although everything seems quite logical to me. Your help would be highly appreciated!
SessionVar.Set("%EarthNav%", a_path .. "\\Custom Data\\earth_nav.dat");
-- Remove lines from earth_nav.dat
-- read earth_nav.dat
mytable = TextFile.ReadToTable("%EarthNav%");
linestable = {};
inc = -1;
-- keyword 1
for line_number,line_content in pairs(mytable) do
result = String.Find(line_content, "CARTER", 1, false); -- false means not case sensitive
if (result > 0) then
inc = inc + 1;
line_number1 = line_number - inc;
Table.Insert(linestable, 1, line_number1);
end
end
-- keyword 2
for line_number,line_content in pairs(mytable) do
result = String.Find(line_content, "KENNEDY", 1, false); -- false means not case sensitive
if (result > 0) then
inc = inc + 1;
line_number1 = line_number - inc;
Table.Insert(linestable, 1, line_number1);
end
end
-- table with line numbers which contain a line which need to be deleted
Table.Sort(linestable, nil)
for x,y in pairs(linestable) do
Table.Remove(mytable, y);
end
-- Write earth_nav.dat
TextFile.WriteFromTable("%EarthNav%", mytable, false);
...so the idea to remove all lines from the file %EarthNav% which contain "Kennedy" or "Carter".
I've got a code to remove lines from a file "%EarthNav%" with defined keywords. It does not seem to work although everything seems quite logical to me. Your help would be highly appreciated!
SessionVar.Set("%EarthNav%", a_path .. "\\Custom Data\\earth_nav.dat");
-- Remove lines from earth_nav.dat
-- read earth_nav.dat
mytable = TextFile.ReadToTable("%EarthNav%");
linestable = {};
inc = -1;
-- keyword 1
for line_number,line_content in pairs(mytable) do
result = String.Find(line_content, "CARTER", 1, false); -- false means not case sensitive
if (result > 0) then
inc = inc + 1;
line_number1 = line_number - inc;
Table.Insert(linestable, 1, line_number1);
end
end
-- keyword 2
for line_number,line_content in pairs(mytable) do
result = String.Find(line_content, "KENNEDY", 1, false); -- false means not case sensitive
if (result > 0) then
inc = inc + 1;
line_number1 = line_number - inc;
Table.Insert(linestable, 1, line_number1);
end
end
-- table with line numbers which contain a line which need to be deleted
Table.Sort(linestable, nil)
for x,y in pairs(linestable) do
Table.Remove(mytable, y);
end
-- Write earth_nav.dat
TextFile.WriteFromTable("%EarthNav%", mytable, false);
...so the idea to remove all lines from the file %EarthNav% which contain "Kennedy" or "Carter".
Comment