How to get 1 string from a file based on a regular expression?

  • Автор темы Автор темы BlackSun
  • Дата начала Дата начала

BlackSun

Client
Регистрация
24.01.2011
Сообщения
119
Реакции
3
Баллы
0
I would like to be able to read and remove just one line from a file based on a regular expression match?

Seems the only option at the moment is to read and remove all lines or a random line or a one line if you know the string number.
 
I dont think its possible, however, thanks for the tip about reading the whole file, regexping it and then saving it again heh
 
You might read it in loop - until you find what you're looking for, then when you have line number you might delete single line.
 
You might read it in loop - until you find what you're looking for, then when you have line number you might delete single line.

That would be one way but it would be very slow at pulling a line from a large file. And if you're running multiple threads, there is always the possibility the contents will have changed before you find the line you need.

You could use a file lock, read the entire file, scan it for the line you need, pull the line based on line number. Then finally unlock the file.
 
Well anyway we defintely need Zenno dev team to add regexp parsing when taking a line, this way well be able to handle txt files like Databases.
 
+1 from me
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)