Skip to main content
added 98 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using standard (non-GNU) sed (which can't insert a newline character using \n with the s command):

$ sed -e 's/[0-9]\{13\}/&:/g' -e 'y/:/\n/' file
5.6568542494924
15.5948709516943
15.5948709516943
15.5948709516943
21.4662525839980
21.4662525839980
21.4662525839980
27.4809024597083

This inserts a : after every run of 13 digits in the input, and then replaces all those colons with newlines using the y command.

Or, using a literal newline:

sed 's/[0-9]\{13\}/&\
/g' file

Or, if your shell understands $'...' strings:

sed $'s/[0-9]\\{13\\}/&\\\n/g' file

Using standard (non-GNU) sed (which can't insert a newline character using \n with the s command):

$ sed -e 's/[0-9]\{13\}/&:/g' -e 'y/:/\n/' file
5.6568542494924
15.5948709516943
15.5948709516943
15.5948709516943
21.4662525839980
21.4662525839980
21.4662525839980
27.4809024597083

This inserts a : after every run of 13 digits in the input, and then replaces all those colons with newlines using the y command.

Or, using a literal newline:

sed 's/[0-9]\{13\}/&\
/g' file

Using standard (non-GNU) sed (which can't insert a newline character using \n with the s command):

$ sed -e 's/[0-9]\{13\}/&:/g' -e 'y/:/\n/' file
5.6568542494924
15.5948709516943
15.5948709516943
15.5948709516943
21.4662525839980
21.4662525839980
21.4662525839980
27.4809024597083

This inserts a : after every run of 13 digits in the input, and then replaces all those colons with newlines using the y command.

Or, using a literal newline:

sed 's/[0-9]\{13\}/&\
/g' file

Or, if your shell understands $'...' strings:

sed $'s/[0-9]\\{13\\}/&\\\n/g' file
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using standard (non-GNU) sed (which can't insert a newline character using \n with the s command):

$ sed -e 's/[0-9]\{13\}/&:/g' -e 'y/:/\n/' file
5.6568542494924
15.5948709516943
15.5948709516943
15.5948709516943
21.4662525839980
21.4662525839980
21.4662525839980
27.4809024597083

This inserts a : after every run of 13 digits in the input, and then replaces all those colons with newlines using the y command.

Or, using a literal newline:

sed 's/[0-9]\{13\}/&\
/g' file