sed Insert a Newline Into the RHS of a Substitution

Q. How do I insert a newline into the RHS of a substitution using sed under Linux / UNIX like operating systems? My line pattern is as follows:

This is a test. This is another input.

I’d like to insert a newline after dot (.).

A. Simple use sed command as follows:

echo 'This is a test. This is another input.' | sed -e 's/./&n/'

echo ‘This is a test. This is another input.’ | sed -e ‘s/./&n/’

You need to substitute dot and simply insert newline (n) to replace with it.
If you are using older sed version try:

echo 'This is a test. This is another input.'  |sed 's/./& 
> /'

echo ‘This is a test. This is another input.’ |sed ‘s/./&
> /’

Sample output:

This is a test. 
 This is another input.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts