Forrest logo
back to the sed tool

linux:files:file:delete:line

Delete a single line from a given file
$ sed -i '${line_number}d' ${filename}
try on your machine

This command uses the sed (stream editor) tool to delete a specific line in a file.

  • '${line_number}d' - This is the command that tells sed to delete a specific line. The curly braces indicate that the line number is a variable. So, replace '${line_number}' with the actual line number you want to delete.
  • ${filename} - This is the name of the file in which you want to delete the line. Replace '${filename}' with the actual name of the file you want to work with.
  • -i - This flag tells sed to edit the file in place (overwrite the original file). Without this flag, sed would only output the modified file to the console.
This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the sed tool