parsed.org

Tips by tag: sed

Add a Newline to the End of a File by cygnus on Dec 31, 2005 04:09 PM

Use sed to add a newline to the end of a file (this will perform an in-place replacement and create a backup file, MYFILE.bak):

$ sed -i.bak '$G' MYFILE

Some programs, such as Emacs, will omit the trailing newline from a file unless configured to add one. Emacs can be configured to add a newline automatically.

backupcommandsconfigurationeditorsemacsin-placeline-endingsnewlinesedshell
In-place Sed Replace by xinu on Jan 12, 2005 11:54 AM

This command will replace occurrences of foo with bar in the file X in-place and create a backup of X in X.old:

$ sed -i.old "s/foo/bar/g" filename
backupcommandsin-placesedshell
Refresh Apache Logs by xinu on Jan 13, 2005 08:45 AM

Clever kill/cat/sed line to refresh the logs for Apache stolen from some documentation somewhere:

# kill -USR1 $(cat $(httpd -V | sed -n '/DEFAULT_PIDLOG/s/.*"\(.*\)"/\1/p'))
apachecommandskillloggingsed
Remove a file's extension with sed by skypher on Jul 31, 2008 04:36 AM

$ echo file.ext1.ext2 | sed 's/.[^.]*$//' file.ext1

extensionfilesedshshell
RSS