Skip to main content
3 of 4
added perl equivalent
steeldriver
  • 83.9k
  • 12
  • 124
  • 175

With GNU sed, you can match each contiguous string (i.e. without whitespace) terminated by : and then place a newline before all but the first one:

sed 's/[^[:space:]]\+:/\n&/g2'

If your version of sed does not support the gn extension, you can use a plain g modifier

sed 's/[^[:space:]]\+:/\n&/g'

which will work the same except for printing an additional newline before the first key. You could use perl -pe 's/\S+:/\n$&/g' with the same proviso (there may be a perl equivalent of the GNU sed g2 but I don't know it).

steeldriver
  • 83.9k
  • 12
  • 124
  • 175