how to delete a specific line in a file

Solutions on MaxInterview for how to delete a specific line in a file by the best coders in the world

showing results for - "how to delete a specific line in a file"
Sakina
03 Nov 2018
1searched = "snow" # every line containing the variable "searched" will be deleted
2
3with open("file.txt","r+") as f: # open your file
4    new_f = f.readlines()
5    f.seek(0)
6    for line in new_f:
7        if searched not in line:
8            f.write(line)
9    f.truncate() # close your file
Tobin
02 Jun 2020
1# Basic syntax:
2sed 'line#d' input_file
3# Where line# is the line you want to delete from the input_file
4
5# Example usage:
6input_file contains:
7this is
8my favorite
9line
10
11sed '2d' input_file
12--> this is
13--> line
queries leading to this page
bash delete line from fileremove the line containing some specific string from a file in bashshell delete some line delete line of file linuxdelete specific line in bashlinux delete line from file by numberhow to remove a line in a file linux using set how to delete lines from a file in bashcommand line delete texthow to delete a particular line in a file using pythonlinux delete specific line from filedelete a line from a filesed remove lines containing stringremove row unix commandshell script to find and delete lines in a filehow to delete a speccific line in a filesed remove lineremove specific line from file linuxdeleting the contents of a line and enetering new text linuxdelete specific line in file pythondelete a line from specific filebash remove lasst tewo lines of filebash delete line in fileremove certain line from a filehow to delete a particular line in shell scriptdelete one line in a file using bashdelete line from file unixhow to delete a specific line in a file pythonunix delete specific lines from filehow to remove a line form file using terminalhow to remove a line from a file in bashhow to remove specific lines from a file in linuxdelete specific line from file unixdelete second line of file unix without using sedhow to delete specific line in file pythonremove a specific line from a file linuxdelete line from file bashhow to delete a specific line in a file in pythondelete specific line from a file pythonhow to remove lines from a filesed delete lines by line numberbash delete specific line pattern from filebash remoce line from filebash delete line from a filehow to delete a specific line in file pythondelete specific line from file linuxbash remove current filedelete a line from file in shell scripthow to delete particular line and range of line in sedhow to remove lines from teh file int he terminalshell delete line from filehwo to delete certain lines ina file linux commandremove a line from a file bashremove lines matching 2c in specific filehow to delete a specific line in a fileif file contains specific word 2c delete file bashhow to delete specific line in filehow to remove certain line thath have word in kali terminalpython delete certain line in filecommand line delete line from filedelete specific lines in file pythonremove line from file bashdelete specific line in text file pythonremove current linein file bashhow to delete certain lines from a file in pythonlinux remove specific line from filehow to remove a line number in a file linux using sethow to remove specific line from file pythondelete specific line in file bashdelete line from file in bashremove certain line bashsh delete line from fileunix command delete a line in a filehow to remove a line in a file linuxhow to delete line of text in linuxwrite file delete lineshow to delete specific line in text file pythonhow to remove a specific line from a file pythonbash delete specific line from filedelete a specific line seddelete some lines of a filedelete second line of file unixhow to delte a line from a text file using linuxbash how to delete a specific line from a filedelete certain lines from a file in unixhow to remove a line from a file shellbash remove line from all filesremove particular line from fileshow to remove particular line from file in pythondelete lines in file shell scripthow to remove specefic line email using kaliremoving a line from a file which has specific character in shell how to remove a specific line from a file in pythonhow to delete specific file lines pythonremove line number with sedremoving a line from a file which has specific character delete in file specific line shellhow to delete a specific line in a file