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

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.
 

backlinker

Новичок
Регистрация
25.03.2011
Сообщения
17
Благодарностей
2
Баллы
0
I dont think its possible, however, thanks for the tip about reading the whole file, regexping it and then saving it again heh
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
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.
 

BlackSun

Client
Регистрация
24.01.2011
Сообщения
119
Благодарностей
3
Баллы
0
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.
 

backlinker

Новичок
Регистрация
25.03.2011
Сообщения
17
Благодарностей
2
Баллы
0
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.
 

Stereomike

Client
Регистрация
29.03.2011
Сообщения
221
Благодарностей
30
Баллы
0
+1 from me
 

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