Skip to content

Instantly share code, notes, and snippets.

@agile6v
Created November 3, 2018 10:24
Show Gist options
  • Save agile6v/6cc97177ede8a32ca4ed36f668659451 to your computer and use it in GitHub Desktop.
Save agile6v/6cc97177ede8a32ca4ed36f668659451 to your computer and use it in GitHub Desktop.
Replace all newline with a comma except the last line
sed -n '1h;1!H;${g;s/\n/,/g;p;}'
For example:
ip a | grep inet | grep -v inet6 |sed 's/^[ \t]*//g' | cut -d ' ' -f2 | sed -n '1h;1!H;${g;s/\n/,/g;p;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment