ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Something like this would do. You didn't mention which language you are using, so I will give you the solution in a random language. I'm sure it will help you:
Code:
Public Function DeleteLine(fName As String, LineNumber As Long) _
As Boolean
'Purpose: Deletes a Line from a text file
'Parameters: fName = FullPath to File
' LineNumber = LineToDelete
'Returns: True if Successful, false otherwise
'Requires: Reference to Microsoft Scripting Runtime
'Example: DeleteLine("C:\Myfile.txt", 3)
' Deletes third line of Myfile.txt
'______________________________________________________________
Dim oFSO As New FileSystemObject
Dim oFSTR As Scripting.TextStream
Dim ret As Long
Dim lCtr As Long
Dim sTemp As String, sLine As String
Dim bLineFound As Boolean
On Error GoTo ErrorHandler
If oFSO.FileExists(fName) Then
Set oFSTR = oFSO.OpenTextFile(fName)
lCtr = 1
Do While Not oFSTR.AtEndOfStream
sLine = oFSTR.ReadLine
If lCtr <> LineNumber Then
sTemp = sTemp & sLine & vbCrLf
Else
bLineFound = True
End If
lCtr = lCtr + 1
Loop
oFSTR.Close
Set oFSTR = oFSO.CreateTextFile(fName, True)
oFSTR.Write sTemp
DeleteLine = bLineFound
End If
ErrorHandler:
On Error Resume Next
oFSTR.Close
Set oFSTR = Nothing
Set oFSO = Nothing
End Function
hi
i have another problem with this
i would not like to remove the line.
just wanna do some changes in the line..
for example "disable_from_plugins" , this is the word containing the line
search the line and change the line i.e
rame("rr.disable_from_plugins", 2);
to
"rame("rr.disable_from_plugins", 1);"
and save by programatically
This simple script takes the string "Copyright 1999-2005 - All rights reserved" from all the html files in the directory where it is run and replaces it with "Copyright 1999-2007 - All rights reserved" and makes a backup as well... Hope it is of use.
for file in *.html
do
cp $file $file.bak &&
sed 's/Copyright 1999-2005 - All rights reserved/Copyright 1999-2007 - All rights reserved/g' $file.bak >$file
done
This simple script takes the string "Copyright 1999-2005 - All rights reserved" from all the html files in the directory where it is run and replaces it with "Copyright 1999-2007 - All rights reserved" and makes a backup as well... Hope it is of use.
for file in *.html
do
cp $file $file.bak &&
sed 's/Copyright 1999-2005 - All rights reserved/Copyright 1999-2007 - All rights reserved/g' $file.bak >$file
done
it is not helpfull..
previously i used
sed -i '/disable_from_plugins/d' munna.c
to delete the line
but i would like to change the text in that line and save in that file only..
i dont wanna use redirecting file..
can you help me
like one line command to do this operation ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.