Skip to content

Instantly share code, notes, and snippets.

@mayurah
Last active August 29, 2015 14:04
Show Gist options
  • Save mayurah/2565f55ae695ea56b97a to your computer and use it in GitHub Desktop.
Save mayurah/2565f55ae695ea56b97a to your computer and use it in GitHub Desktop.
Sed one-liner
Remove leading and trailing whitespace
# sed 's/^[ \t]*//;s/[ \t]*$//' filename
Replace newline (\n) with ",," (imperfect)
# sed ':a;N;$!ba;s/\n/,/g' filename
simple replace ",," with newline (\n)
# sed 's/,,/\n/g' filename
prepend "##" to each line
# sed 's/^/##/' filename
** more sources **
* http://sed.sourceforge.net/sed1line.txt
* http://www-rohan.sdsu.edu/doc/sed.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment