/    Sign up×
Community /Pin to ProfileBookmark

how to remove a single line from a text file

Hi guys,

my question is really simple.
How do I remove 1 line from a text file.

example:
I have a .htpasswd file with several entry.
I would like to remove the line which contain the login: bob

How do I do that when I don’t want to put the file in an array, remove the entry from the array and then re write the file with the new array content.

Tks in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pyroMay 21.2003 — I think you are going to have to do it that way. Reading from a file automatically puts the contents into an array, so it is logical that to remove a line, you loop through, remove the line, and re-write... Why can't you do it that way?
Copy linkTweet thisAlerts:
@jchibbraauthorMay 21.2003 — I thought there was another way to do it more efficiently.

like open the file, read and cut the line and save the file.

Tks anyway
×

Success!

Help @jchibbra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...