Skip to content

Instantly share code, notes, and snippets.

@CodigoMatriz
Last active August 26, 2021 00:06
Show Gist options
  • Save CodigoMatriz/7eed771aa2e9ff14de0b55dc06c778c6 to your computer and use it in GitHub Desktop.
Save CodigoMatriz/7eed771aa2e9ff14de0b55dc06c778c6 to your computer and use it in GitHub Desktop.
[Remove line with "sed"] Using sed to remove a line in a file #cli #sed

GNU sed

sed -i "37d" /path/to/file

sed in macOS runs a bit differently than GNU as you have to define a backup file extension before editing the original file:

sed -i.bak "37d" /path/to/file

Both of the above will remove line 37 from the specified file.

d is the command to delete a pattern space, while 37 stands for the 37th line.

In macOS it will create a backup of the original file first based on the extension given after the -i flag, in this case being .bak. A /path/to/file.bak will be created and the original file will be updated with the removed line 37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment