Skip to content

How to Append Blank Lines to Files on Linux

How to Distinguish Carriage Returns CR, Line Feeds LF, and New Lines CRLF on Linux
I assume that you have read my previous post. In that post, I mentioned about how to echo an empty line or a new line n. Let's see the original file in this example:
[root@localhost ~]$ cat -n temp.txt
     1  My name is Ed Chen, you can call me Eddie. Here is my profile at : Google+. I live in Taipei, Taiwan and work as a Technical Supervisor at MDS System, Taiwan.

There's only one line in the file.

If you'd like to append only 1 empty line to a file, you can do this:
[root@localhost ~]$ echo >> temp.txt
If you want 2 empty lines, you can do this:
[root@localhost ~]$ echo $'n' >> temp.txt
If you want 3 empty lines, you can do this:
[root@localhost ~]$ echo $'n'$'n' >> temp.txt
[root@localhost ~]$ cat -n temp.txt
     1  My name is Ed Chen, you can call me Eddie. Here is my profile at : Google+. I live in Taipei, Taiwan and work as a Technical Supervisor at MDS System, Taiwan.
     2
     3
     4

And so on, you can predict that there will be 9 $'n' concatenated in the command to meet 10 empty lines.

Leave a Reply

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